Part Number Hot Search : 
SIR862DP 2SA1493 C2229 0M100 FR9024N STTH2002 TC4093BF D2412
Product Description
Full Text Search
 

To Download C8051F321 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  full speed usb, 16k isp flash mcu family c8051f320/1 preliminary rev. 1.1 12/03 copyright ? 200 3 by silicon laboratories c8051f320/1-ds11 this information applies to a product under dev elopment. its characteristics and specifications are s ubject to change without n otice. analog peripherals - 10-bit adc ? up to 200 ksps ? up to 17 or 13 external single-ended or differential inputs ? vref from external pin, internal reference, or vdd ? built-in temperature sensor ? external conversion start input - two comparators - internal voltage reference - por/brown-out detector usb function controller - usb specification 2.0 compliant - full speed (12 mbps) or low speed (1.5 mbps) operation - integrated clock recovery ; no external crystal required for full speed or low speed - supports eight flexible endpoints - 1k byte usb buffer memory - integrated transceiver; no external resistors required on-chip debug - on-chip debug circuitry fa cilitates fu ll speed, non-intrusive in-system debug (no emulator required!) - provides breakpoints, single stepping, inspect/modify memo ry and registers - superior performance to emulation systems using ice-chips, target pods, and sockets voltage regulator input: 4.0v to 5.25v high speed 8051 c core - pipelined instruction archite cture; executes 70% of instructions in 1 or 2 system clocks - up to 25 mips throughput with 25 mhz clock - expanded interrupt handler memory - 2304 bytes internal ram (1k + 256 + 1k usb fifo) - 16k bytes flash; in-system programmable in 512-byte sectors digital peripherals - 25/21 port i/o; all 5 v tolerant with high sink current - hardware enhanced spi?, enhanced uart, and smbus? serial ports - four general purpose 16-bit counter/timers - 16-bit programmable counter array (pca) with five capture/compare modules - real time clock mode using external clock source and pca or timer clock sources - internal oscillator: 0.25 % accuracy with clock recovery enabled. supports all usb and uart modes - external oscillator: crystal, rc, c, or clock (1 or 2 pin modes) - can switch between clock sour ces on-the-fly; useful in power saving strategies packages - 32-pin lqfp (c8051f320) - 28-pin mlp (C8051F321) temperature range: -40c to +85c analog peripherals 10-bit 200ksps adc 16kb isp flash 2304 b sram por debug circuitry 16 interrupts 8051 cpu (25mips) digital i/o precision internal oscillator high-speed controller core a m u x crossbar + - wdt + - usb controller / transceiver uart smbus pca timer 0 timer 1 timer 2 timer 3 spi port 0 port 1 port 2 port 3 temp sensor vreg vref ( datasheet : )
c8051f320/1 2 rev. 1.1 notes
c8051f320/1 rev. 1.1 3 table of contents 1. system over view .........................................................................................................17 1.1. cip-51? microcontr oller core ......................................................................................20 1.1.1. fully 8051 compatible ..........................................................................................20 1.1.2. improved thr oughput ............................................................................................20 1.1.3. additional feat ures................................................................................................21 1.2. on-chip memory ............................................................................................................2 2 1.3. universal serial bus controller.......................................................................................23 1.4. voltage regul ator.......................................................................................................... ..23 1.5. on-chip debug ci rcuitry ......... .......................................................................................24 1.6. programmable digital i/o and cro ssbar .........................................................................25 1.7. serial ports............................................................................................................... ........25 1.8. programmable counter array .........................................................................................26 1.9. 10-bit analog to digi tal converter.................................................................................27 1.10. comparators ............................................................................................................... .....28 2. absolute maximum ratings ..................................................................................29 3. global dc electrical characteristics ......................................................30 4. pinout and package definitions........................................................................31 5. 10-bit adc (a dc0) ............................................................................................................ .39 5.1. analog multip lexer ......................................................................................................... 40 5.2. temperature sensor......................................................................................................... 41 5.3. modes of oper ation......................................................................................................... 42 5.3.1. starting a conversion.............................................................................................42 5.3.2. tracking modes .....................................................................................................43 5.3.3. settling time requirements ..................................................................................44 5.4. programmable window detector ....................................................................................50 5.4.1. window detector in si ngle-ended mode .............................................................52 5.4.2. window detector in di fferential mode.................................................................53 6. voltage reference....................................................................................................55 7. comparators ................................................................................................................ 57 8. voltage regulator (reg0) ....................................................................................67 8.1. regulator mode se lection ...............................................................................................68 8.2. vbus detect ion............................................................................................................. .69 9. cip-51 microcontr oller .........................................................................................73 9.1. instruction set............................................................................................................ ......75 9.1.1. instruction and cpu timing..................................................................................75 9.1.2. movx instruction and program memory.............................................................75 9.2. memory organi zation .....................................................................................................79 9.2.1. program memory ...................................................................................................79 9.2.2. data memory .........................................................................................................80 9.2.3. general purpose registers .....................................................................................80 9.2.4. bit addressable locations .....................................................................................80 9.2.5. stack ...................................................................................................................8 0 9.2.6. special function registers.....................................................................................81
c8051f320/1 4 rev. 1.1 9.2.7. register descri ptions .............................................................................................84 9.3. interrupt ha ndler .......................................................................................................... ...87 9.3.1. mcu interrupt sources and vectors .....................................................................87 9.3.2. external inte rrupts .................................................................................................88 9.3.3. interrupt prio rities..................................................................................................88 9.3.4. interrupt late ncy....................................................................................................88 9.3.5. interrupt register descriptions ..............................................................................90 9.4. power management modes .............................................................................................96 9.4.1. idle mode ...............................................................................................................9 6 9.4.2. stop mode..............................................................................................................96 10. reset sources ............................................................................................................. .99 10.1. power-on re set............................................................................................................ .100 10.2. power-fail reset / vdd monitor..................................................................................101 10.3. external reset............................................................................................................ ....102 10.4. missing clock detect or reset .......................................................................................102 10.5. comparator0 re set ........................................................................................................1 02 10.6.pca watchdog timer reset .........................................................................................102 10.7. flash error reset .......................................................................................................10 2 10.8. software reset............................................................................................................ ...103 10.9. usb reset ................................................................................................................. ....103 11. flash memory ............................................................................................................10 7 11.1. programming the flash memory .............................................................................107 11.1.1. flash lock and ke y functions ........................................................................107 11.1.2. flash erase procedure......................................................................................107 11.1.3. flash write procedure .....................................................................................108 11.2. non-volatile data storage .............................................................................................109 11.3. security options .......................................................................................................... ..109 12. external ra m .............................................................................................................1 13 12.1. accessing user xram .................................................................................................113 12.2. accessing usb fi fo space..........................................................................................114 13. oscillators................................................................................................................. ..117 13.1. programmable internal oscillator .................................................................................117 13.1.1. programming the internal oscill ator on c8051f320/1 devices .........................118 13.1.2. internal oscillator suspend mode .......................................................................118 13.2. external oscillator drive circuit...................................................................................120 13.2.1. clocking timers directly thr ough the external oscillator ................................120 13.2.2. external crystal example ....................................................................................120 13.2.3. external rc ex ample ..........................................................................................121 13.2.4. external capacito r example ................................................................................121 13.3. 4x clock mul tiplier ....................................................................................................... 123 13.4. system and usb cloc k selection .................................................................................124 13.4.1. system clock se lection .......................................................................................124 13.4.2. usb clock selection ...........................................................................................124 14. port input/outp ut ...................................................................................................127 14.1. priority crossbar decoder .............................................................................................129
c8051f320/1 rev. 1.1 5 14.2. port i/o initia lization................................................................................................... ..131 14.3.general purpose po rt i/o...............................................................................................134 15. universal serial bus co ntroller (usb0) ....................................................143 15.1. endpoint addre ssing .....................................................................................................14 4 15.2. usb transceiver ........................................................................................................... 144 15.3. usb register access.....................................................................................................14 6 15.4.usb clock config uration .............................................................................................150 15.5. fifo management.........................................................................................................15 1 15.5.1. fifo split mode ..................................................................................................151 15.5.2. fifo double buff ering .......................................................................................151 15.5.3. fifo access ........................................................................................................152 15.6. function addre ssing......................................................................................................1 53 15.7. function configurati on and control .............................................................................154 15.8. interrupts ................................................................................................................ .......157 15.9. the serial interf ace engine ...........................................................................................161 15.10.endpoint0 ................................................................................................................ .....161 15.10.1.endpoint0 setup tr ansactions .........................................................................162 15.10.2.endpoint0 in tran sactions .................................................................................162 15.10.3.endpoint0 out tran sactions .............................................................................163 15.11.configuring endpoi nts1-3 ...........................................................................................166 15.12.controlling endpoint s1-3 in .......................................................................................166 15.12.1.endpoints1-3 in interrupt or bulk mode ...........................................................166 15.12.2.endpoints1-3 in is ochronous mode...................................................................167 15.13.controlling endpoi nts1-3 out ...................................................................................170 15.13.1.endpoints1-3 out interrupt or bulk mode .......................................................170 15.13.2.endpoints1-3 out is ochronous mode...............................................................170 16. smbus....................................................................................................................... ...........175 16.1. supporting docume nts ..................................................................................................176 16.2. smbus configuration....................................................................................................176 16.3. smbus operation ..........................................................................................................1 77 16.3.1. arbitratio n............................................................................................................1 77 16.3.2. clock low exte nsion...........................................................................................178 16.3.3. scl low timeout ...............................................................................................178 16.3.4. scl high (smbus fr ee) timeout.......................................................................178 16.4. using the sm bus........................................................................................................... 179 16.4.1. smbus configurati on register............................................................................180 16.4.2. smb0cn control register ..................................................................................183 16.4.3. data regist er........................................................................................................186 16.5. smbus transfer modes.................................................................................................187 16.5.1. master transmitter mode ....................................................................................187 16.5.2. master receiver mode.........................................................................................188 16.5.3. slave receiver mode ...........................................................................................189 16.5.4. slave transmitter mode.......................................................................................190 16.6. smbus status de coding................................................................................................191 17. uart0 ....................................................................................................................... ...........193
c8051f320/1 6 rev. 1.1 17.1. enhanced baud rate generation...................................................................................194 17.2. operational m odes ........................................................................................................1 95 17.2.1. 8-bit uart .........................................................................................................195 17.2.2. 9-bit uart .........................................................................................................196 17.3. multiprocessor co mmunications...................................................................................197 18. enhanced serial peripher al interface (spi0) .........................................203 18.1. signal descri ptions....................................................................................................... .204 18.1.1. master out, slave in (mosi) ..............................................................................204 18.1.2. master in, slave out (miso) ..............................................................................204 18.1.3. serial clock (sck) ..............................................................................................204 18.1.4. slave select (nss)...............................................................................................204 18.2. spi0 master mode operation ........................................................................................205 18.3. spi0 slave mode op eration ..........................................................................................207 18.4. spi0 interrupt sources...................................................................................................2 07 18.5. serial clock timing ......................................................................................................2 08 18.6. spi special function registers .....................................................................................210 19. timers ..................................................................................................................... ..........217 19.1. timer 0 and timer 1......................................................................................................2 17 19.1.1. mode 0: 13-bit co unter/timer.............................................................................217 19.1.2. mode 1: 16-bit co unter/timer.............................................................................218 19.1.3. mode 2: 8-bit counter/time r with auto-reload .................................................219 19.1.4. mode 3: two 8-bit counter/t imers (timer 0 only) ...........................................220 19.2. timer 2 ................................................................................................................... ....225 19.2.1. 16-bit timer with auto-reload ...........................................................................225 19.2.2. 8-bit timers with auto-reload............................................................................226 19.2.3. usb start-of-frame capture ...............................................................................227 19.3. timer 3 ................................................................................................................... ....230 19.3.1. 16-bit timer with auto-reload ...........................................................................230 19.3.2. 8-bit timers with auto-reload............................................................................231 19.3.3. usb start-of-frame capture ...............................................................................232 20. programmable counter array (pca0) .........................................................235 20.1. pca counter/t imer.......................................................................................................23 6 20.2. capture/compare modules............................................................................................237 20.2.1. edge-triggered capture mode .............................................................................238 20.2.2. software timer (c ompare) mode........................................................................239 20.2.3. high speed output mode ....................................................................................240 20.2.4. frequency output mode ......................................................................................241 20.2.5. 8-bit pulse width m odulator mode ....................................................................242 20.2.6. 16-bit pulse width m odulator mode ..................................................................244 20.3. watchdog timer mode..................................................................................................246 20.3.1. watchdog timer op eration .................................................................................246 20.3.2. watchdog timer usage .......................................................................................247 20.4. register descriptions for pca ......................................................................................248 21. c2 interface ................................................................................................................ ..253 21.1.c2 interface re gisters ...................................................................................................2 53
c8051f320/1 rev. 1.1 7 21.2. c2 pin sharing............................................................................................................ ...255
c8051f320/1 8 rev. 1.1 notes
c8051f320/1 rev. 1.1 9 list of figures and tables 1. system overvi ew ........................................................................................................17 table 1.1. product sel ection guide ......................................................................................17 figure 1.1. c8051f320 bloc k diagram.................................................................................18 figure 1.2. C8051F321 bloc k diagram.................................................................................19 figure 1.3. comparison of peak mcu execution speeds.....................................................20 figure 1.4. on-chip clock and reset....................................................................................21 figure 1.5. on-board memory map ......................................................................................22 figure 1.6. usb controller block diagram ..........................................................................23 figure 1.7. development/in-s ystem debug diagram ...........................................................24 figure 1.8. digital crossbar diagram....................................................................................25 figure 1.9. pca block diagram............................................................................................26 figure 1.10. pca block diagram............................................................................................26 figure 1.11. 10-bit adc block diagram................................................................................27 figure 1.12. comparator0 block diagram ..............................................................................28 2. absolute maximum ratings .................................................................................29 table 2.1. absolute maximum ratings*..............................................................................29 3. global dc electrical characteristics .....................................................30 table 3.1. global dc electrica l characteristics...................................................................30 4. pinout and package definitions .......................................................................31 table 4.1. pin definitions fo r the c8051f320/1 ..................................................................31 figure 4.1. lqfp-32 pinout diagram (top view)................................................................33 figure 4.2. lqfp-32 package diagram.................................................................................34 table 4.2. lqfp-32 packag e dimensions............................................................................34 figure 4.3. mlp-28 pinout diag ram (top view) .................................................................35 figure 4.4. mlp-28 package drawing ..................................................................................36 table 4.3. mlp-28 packag e dimensions .............................................................................36 figure 4.5. typical mlp-28 landing diagram .....................................................................37 figure 4.6. typical mlp- 28 solder mask .............................................................................38 5. 10-bit adc (a dc0) ........................................................................................................... .39 figure 5.1. adc0 functiona l block diagram .......................................................................39 figure 5.2. typical temperature se nsor transfer function..................................................41 figure 5.3. 10-bit adc track and conversion example timing.........................................43 figure 5.4. adc0 equivalent input circuits .........................................................................44 figure 5.5. amx0p: amux0 positive channel select register..........................................45 figure 5.6. amx0n: amux0 negative channel select register........................................46 figure 5.7. adc0cf: adc0 conf iguration regi ster ...........................................................47 figure 5.8. adc0h: adc0 data word msb register.........................................................47 figure 5.9. adc0l: adc0 data word lsb register ..........................................................48 figure 5.10. adc0cn: adc0 c ontrol register .....................................................................49 figure 5.11. adc0gth: adc0 greater-tha n data high byte register...............................50 figure 5.12. adc0gtl: adc0 greater-tha n data low byte register ................................50 figure 5.13. adc0lth: adc0 less-than data high byte register ....................................51 figure 5.14. adc0ltl: adc0 less-than data low byte register .....................................51
c8051f320/1 10 rev. 1.1 figure 5.15. adc window compare example: right-justified single-ended data..............52 figure 5.16. adc window compare example: left-justified single-ended data ................52 figure 5.17. adc window compare example: ri ght-justified differ ential data.................53 figure 5.18. adc window compare example: le ft-justified differential data ...................53 table 5.1. adc0 electrical characteristics..........................................................................54 6. voltage reference ...................................................................................................55 figure 6.1. voltage reference f unctional block diagram....................................................55 figure 6.2. ref0cn: referen ce control register ................................................................56 table 6.1. voltage reference elec trical characteristics ......................................................56 7. comparators ............................................................................................................... 57 figure 7.1. comparator0 functi onal block diag ram ............................................................57 figure 7.2. comparator1 functi onal block diag ram ............................................................58 figure 7.3. comparator hy steresis plot.................................................................................59 figure 7.4. cpt0cn: comparator 0 control register ...........................................................60 figure 7.5. cpt0mx: comparator0 mux selection register..............................................61 figure 7.6. cpt0md: comparator0 mode selection register..............................................62 figure 7.7. cpt1cn: comparator 1 control register ...........................................................63 figure 7.8. cpt1mx: comparator1 mux selection register..............................................64 figure 7.9. cpt1md: comparator1 mode selection register..............................................65 table 7.1. comparator electri cal characteristics.................................................................66 8. voltage regulato r (reg0) ...................................................................................67 table 8.1. voltage regulator elec trical specifi cations........................................................69 figure 8.1. reg0 configurati on: usb bus-powered ...........................................................70 figure 8.2. reg0 configurati on: usb self-powered ...........................................................70 figure 8.3. reg0 configuration: usb se lf-powered, regulator disabled ..........................71 figure 8.4. reg0 configuration: no usb connection ........................................................71 figure 8.5. reg0cn: voltage regulator control.................................................................72 9. cip-51 microcontr oller ........................................................................................73 figure 9.1. cip-51 bloc k diagram ........................................................................................73 table 9.1. cip-51 instructio n set summary.........................................................................75 figure 9.2. memory map .......................................................................................................79 table 9.2. special function regist er (sfr) memory map..................................................81 table 9.3. special functi on registers ..................................................................................81 figure 9.3. dpl: data po inter low byte ..............................................................................84 figure 9.4. dph: data pointer high byte .............................................................................84 figure 9.5. sp: stack pointer .................................................................................................8 5 figure 9.6. psw: program status word ................................................................................85 figure 9.7. acc: accu mulator..............................................................................................86 figure 9.8. b: b register ...................................................................................................... .86 table 9.4. interrupt summary...............................................................................................89 figure 9.9. ie: interrupt enable .............................................................................................90 figure 9.10. ip: interrupt priority ............................................................................................ 91 figure 9.11. eie1: extended interrupt enable 1 .....................................................................92 figure 9.12. eip1: extended inte rrupt priority 1.....................................................................93 figure 9.13. eie2: extended interrupt enable 2 .....................................................................94
c8051f320/1 rev. 1.1 11 figure 9.14. eip2: extended inte rrupt priority 2.....................................................................94 figure 9.15. it01cf: int0/int1 c onfiguration re gister ......................................................95 figure 9.16. pcon: power control register ..........................................................................97 10. reset sources ............................................................................................................ .99 figure 10.1. reset sources ..................................................................................................... .99 figure 10.2. power-on and vdd monitor reset timing .....................................................100 figure 10.3. vdm0cn: vdd m onitor control ....................................................................101 figure 10.4. rstsrc: reset source register.......................................................................104 table 10.1. reset electrical characteristics .........................................................................105 11. flash memory ...........................................................................................................10 7 table 11.1. flash electrical characteristics .....................................................................108 figure 11.1. flash program memory map and security byte...........................................110 figure 11.2. psctl: program store r/w control ................................................................110 figure 11.3. flkey: flash lock and key register .........................................................111 figure 11.4. flscl: flash scale register ........................................................................111 12. external ram ............................................................................................................1 13 figure 12.1. external ram memory map..............................................................................113 figure 12.2. xram memory map expanded view .............................................................114 figure 12.3. emi0cn: external memo ry interface control .................................................115 13. oscillators ................................................................................................................ ..117 figure 13.1. oscillator diagram ............................................................................................117 figure 13.2. oscicn: internal osci llator control register .................................................119 figure 13.3. oscicl: internal oscill ator calibration register ............................................119 figure 13.4. oscxcn: external osci llator control re gister...............................................122 figure 13.5. clkmul: clock multip lier control register..................................................123 table 13.1. typical usb full sp eed clock settings ...........................................................124 table 13.2. typical usb low sp eed clock settings...........................................................124 figure 13.6. clksel: clock select regi ster .......................................................................125 table 13.3. internal oscillator el ectrical characteristics.....................................................126 14. port input/outp ut ..................................................................................................127 figure 14.1. port i/o functional block diagram ..................................................................127 figure 14.2. port i/o cell block diagram.............................................................................128 figure 14.3. crossbar priority dec oder with no pins skipped .............................................129 figure 14.4. crossbar priority decode r with crystal pins skipped ......................................130 figure 14.5. xbr0: port i/o cr ossbar regist er 0 .................................................................132 figure 14.6. xbr1: port i/o cr ossbar regist er 1 .................................................................133 figure 14.7. p0: port0 register......... .....................................................................................13 5 figure 14.8. p0mdin: port0 input mode register ...............................................................135 figure 14.9. p0mdout: port0 output mode register.........................................................136 figure 14.10. p0skip: port 0 skip register...........................................................................136 figure 14.11. p1: port 1 register ............................................................................................137 figure 14.12. p1mdin: port1 i nput mode register .............................................................137 figure 14.13. p1mdout: port1 ou tput mode register.......................................................138 figure 14.14. p1skip: port 1 skip register...........................................................................138 figure 14.15. p2: port 2 register ............................................................................................139
c8051f320/1 12 rev. 1.1 figure 14.16. p2mdin: port2 i nput mode register .............................................................139 figure 14.17. p2mdout: port2 ou tput mode register.......................................................140 figure 14.18. p2skip: port 2 skip register...........................................................................140 figure 14.19. p3: port 3 register ............................................................................................141 figure 14.20. p3mdin: port3 i nput mode register .............................................................141 figure 14.21. p3mdout: port3 ou tput mode register.......................................................142 table 14.1. port i/o dc electrical charac teristics ..............................................................142 15. universal serial bus co ntroller (usb0) ...................................................143 figure 15.1. usb0 block diagram........................................................................................143 table 15.1. endpoint addr essing scheme............................................................................144 figure 15.2. usb0xcn: usb0 tr ansceiver control............................................................145 figure 15.3. usb0 register access scheme .........................................................................146 figure 15.4. usb0adr: usb0 indi rect address re gister ...................................................147 figure 15.5. usb0dat: usb0 data register ......................................................................148 figure 15.6. index: usb0 endpoint index (usb register) ...............................................148 table 15.2. usb0 controll er registers ................................................................................149 figure 15.7. clkrec: clock recovery control (usb register) ........................................150 figure 15.8. usb fifo allocation ........................................................................................151 table 15.3. fifo confi gurations .........................................................................................152 figure 15.9. fifon: usb0 endpoint fi fo access (usb registers) ...................................152 figure 15.10. faddr: usb0 functi on address (usb register) ........................................153 figure 15.11. power: usb0 po wer (usb register) ..........................................................155 figure 15.12. framel: us b0 frame number low (usb register) .................................156 figure 15.13. frameh: usb0 frame nu mber high (usb register) ................................156 figure 15.14. in1int: usb0 in endpoint interrupt (usb register)...................................157 figure 15.15. out1int: usb0 out endpoi nt interrupt (usb register).............................158 figure 15.16. cmint: us b0 common interrupt (usb register)........................................159 figure 15.17. in1ie: usb0 in endpoint in terrupt enable (usb register) .........................160 figure 15.18. out1ie: usb0 out endpoint in terrupt enable (usb register)....................160 figure 15.19. cmie: usb0 common interrupt enab le (usb register) ..............................161 figure 15.20. e0csr: usb0 endpoint 0 control (usb register) ........................................164 figure 15.21. e0cnt: usb0 endpoint 0 data count (usb register) .................................165 figure 15.22. eincsrl: usb0 in endpoint control high by te (usb register) ...............168 figure 15.23. eincsrh: usb0 in endpoint control low byte (usb register) ...............169 figure 15.24. eoutcsrl: usb0 out endpoint control high byte (usb register) .......171 figure 15.25. eoutcsrh: usb0 out endpoint control low byte (usb register) .......172 figure 15.26. eoutcntl: usb0 out endpoi nt count low (usb register) ..................172 figure 15.27. eoutcnth: usb0 out endpo int count high (usb register) .................172 table 15.4. usb transceiver electr ical characteri stics ......................................................173 16. smbus ...................................................................................................................... ...........175 figure 16.1. smbus bloc k diagram .....................................................................................175 figure 16.2. typical smbus configuration ..........................................................................176 figure 16.3. smbus tran saction ...........................................................................................177 table 16.1. smbus clock sour ce selection.........................................................................180 figure 16.4. typical smbus scl generation.......................................................................181
c8051f320/1 rev. 1.1 13 table 16.2. minimum sda setup and hold times .............................................................181 figure 16.5. smb0cf: smbus clock/ configuration register .............................................182 figure 16.6. smb0cn: smbus control register .................................................................184 table 16.3. sources for hardware changes to smb0cn ....................................................185 figure 16.7. smb0dat: smbus data register ...................................................................186 figure 16.8. typical master tr ansmitter seque nce...............................................................187 figure 16.9. typical master receiver sequ ence ...................................................................188 figure 16.10. typical slave receiver sequ ence ...................................................................189 figure 16.11. typical slave tr ansmitter seque nce ...............................................................190 table 16.4. smbus status decoding....................................................................................191 17. uart0 ...................................................................................................................... ...........193 figure 17.1. uart0 block diagram.....................................................................................193 figure 17.2. uart0 baud rate logic ..................................................................................194 figure 17.3. uart interconnect diagram ............................................................................195 figure 17.4. 8-bit uart timing diagram ...........................................................................195 figure 17.5. 9-bit uart timing diagram ...........................................................................196 figure 17.6. uart multi-processor mode interconnect diagram .......................................197 figure 17.7. scon0: serial port 0 control register.............................................................198 figure 17.8. sbuf0: serial (uart0) port data buffer register .........................................199 table 17.1. timer settings for standard baud rates using the intern al oscillator ...........200 table 17.2. timer settings for standard baud rates using an external oscillator.............200 table 17.3. timer settings for standard baud rates using an external oscillator.............201 table 17.4. timer settings for standard baud rates using an external oscillator.............201 table 17.5. timer settings for standard baud rates using an external oscillator.............202 table 17.6. timer settings for standard baud rates using an external oscillator.............202 18. enhanced serial peripher al interface (spi0) ........................................203 figure 18.1. spi block diagram............................................................................................203 figure 18.2. multiple-master mode connection diagram ....................................................206 figure 18.3. 3-wire single master and 3-wire single slave mode connection diagram ...206 figure 18.4. 4-wire single master mode and 4-wire slave mode connection diagram ....206 figure 18.5. master mode da ta/clock ti ming......................................................................208 figure 18.6. slave mode data/clo ck timing (ckp ha = 0) ................................................209 figure 18.7. slave mode data/clo ck timing (ckp ha = 1) ................................................209 figure 18.8. spi0cfg: spi0 conf iguration register............................................................210 figure 18.9. spi0cn: spi0 control register ........................................................................211 figure 18.10. spi0ckr: spi0 cl ock rate register ..............................................................212 figure 18.11. spi0dat: spi 0 data register ........................................................................213 figure 18.12. spi master t iming (ckpha = 0)...................................................................214 figure 18.13. spi master t iming (ckpha = 1)...................................................................214 figure 18.14. spi slave ti ming (ckpha = 0) .....................................................................215 figure 18.15. spi slave ti ming (ckpha = 1) .....................................................................215 table 18.1. spi slave timi ng parameters............................................................................216 19. timers .................................................................................................................... ..........217 figure 19.1. t0 mode 0 block diagram................................................................................218 figure 19.2. t0 mode 2 block diagram................................................................................219
c8051f320/1 14 rev. 1.1 figure 19.3. t0 mode 3 block diagram................................................................................220 figure 19.4. tcon: timer c ontrol register.........................................................................221 figure 19.5. tmod: timer mode register...........................................................................222 figure 19.6. ckcon: clock control register......................................................................223 figure 19.7. tl0: timer 0 low byte ....................................................................................224 figure 19.8. tl1: timer 1 low byte ....................................................................................224 figure 19.9. th0: time r 0 high byte ...................................................................................224 figure 19.10. th1: time r 1 high byte .................................................................................224 figure 19.11. timer 2 16-bit mode bloc k diagram .............................................................225 figure 19.12. timer 2 8-bit mode block diagram ...............................................................226 figure 19.13. timer 2 so f capture mode (t2split = ?0?) ................................................227 figure 19.14. timer 2 so f capture mode (t2split = ?1?) ................................................227 figure 19.15. tmr2cn: timer 2 control register ..............................................................228 figure 19.16. tmr2rll: timer 2 re load register low byte ............................................229 figure 19.17. tmr2rlh: timer 2 re load register high byte ...........................................229 figure 19.18. tmr2l: ti mer 2 low byte ............................................................................229 figure 19.19. tmr2h time r 2 high byte ............................................................................229 figure 19.20. timer 3 16-bit mode bloc k diagram .............................................................230 figure 19.21. timer 3 8-bit mode block diagram ...............................................................231 figure 19.22. timer 3 so f capture mode (t3split = ?0?) ................................................232 figure 19.23. timer 3 so f capture mode (t3split = ?1?) ................................................232 figure 19.24. tmr3cn: timer 3 control register ..............................................................233 figure 19.25. tmr3rll: timer 3 re load register low byte ............................................234 figure 19.26. tmr3rlh: timer 3 re load register high byte ...........................................234 figure 19.27. tmr3l: ti mer 3 low byte ............................................................................234 figure 19.28. tmr3h time r 3 high byte ............................................................................234 20. programmable counter array (pca0) ........................................................235 figure 20.1. pca block diagram..........................................................................................235 figure 20.2. pca counter/timer block diagram .................................................................236 table 20.1. pca timebase input options............................................................................236 figure 20.3. pca interrupt block diagram...........................................................................237 table 20.2. pca0cpm register settings for pca capture/compare modules..................237 figure 20.4. pca capture mode diagram ............................................................................238 figure 20.5. pca software timer mode diagram................................................................239 figure 20.6. pca high speed output mode diagram ..........................................................240 figure 20.7. pca frequency output mode ...........................................................................241 figure 20.8. pca 8-bit pwm mode diagram ......................................................................243 figure 20.9. pca 16-bit pwm mode ...................................................................................244 figure 20.10. pca module 4 with watchdog timer enabled ..............................................246 table 20.3. watchdog timer ti meout intervals? ................................................................247 figure 20.11. pca0cn: pca control register ....................................................................248 figure 20.12. pca0md: pca mode register ......................................................................249 figure 20.13. pca0cpmn: pca captur e/compare mode registers ...................................250 figure 20.14. pca0l: pca c ounter/timer low byte .........................................................251 figure 20.15. pca0h: pca count er/timer high byte ........................................................251
c8051f320/1 rev. 1.1 15 figure 20.16. pca0cpln: pca capt ure module lo w byte ................................................252 figure 20.17. pca0cphn: pca ca pture module high byte ...............................................252 21. c2 interface ............................................................................................................... ..253 figure 21.1. c2add: c2 address register ..........................................................................253 figure 21.2. deviceid: c2 device id register .................................................................253 figure 21.3. revid: c2 revi sion id register .....................................................................254 figure 21.4. fpctl: c2 flash pr ogramming control register ........................................254 figure 21.5. fpdat: c2 flash pr ogramming data register ............................................254 figure 21.6. typical c2 pin sharing .....................................................................................255
c8051f320/1 16 rev. 1.1 notes
c8051f320/1 rev. 1.1 17 1. system overview c8051f320/1 devices are fully integrated mixed-signal sy stem-on-a-chip mcus. highli ghted features are listed below. refer to table 1.1 for specific product feature selection. ? high-speed pipelined 8051-compatible microcontroller core (up to 25 mips) ? in-system, full-speed, non-intrusive debug interface (on-chip) ? universal serial bus (usb) function controller with eigh t flexible endpoint pipes, integrated transceiver, and 1k fifo ram ? supply voltage regulator (5v-to-3v) ? true 10-bit 200 ksps 17-channel single-ended/differential adc with analog multiplexer ? on-chip voltage reference and temperature sensor ? on-chip voltage comparators (2) ? precision programmable 12 mhz internal oscillator and 4x clock multiplier ? 16k bytes of on-chip flash memory ? 2304 total bytes of on-chip ram (256 + 1k + 1k usb fifo) ?smbus/i 2 c, enhanced uart, and enhanced spi se rial interfaces implemented in hardware ? four general-purpose 16-bit timers ? programmable counter/timer array (pca) with five capture/compare modules and watchdog timer function ? on-chip power-on reset, vdd monitor, and missing clock detector ? 25/21 port i/o (5v tolerant) with on-chip power-on reset, vdd monitor, voltage regulator, watchdog timer, and clock oscillator, c8051f320/1 devices are truly stand-alone system-on-a- chip solutions. the flash memory can be reprogrammed in-circuit, providing non-volatile data st orage, and also allowing field upgrade s of the 8051 firmware. user software has complete control of all peripherals, and may individu ally shut down any or all peripherals for power savings. the on-chip silicon labs 2-wire (c2) development interface allows non-intrusive (uses no on-chip resources), full speed, in-circuit debugging using the production mcu installed in the final application. this debug logic supports inspection and modification of memory and registers, setti ng breakpoints, single stepping, run and halt commands. all analog and digital peripherals are fully functional while debugging using c2. the two c2 interface pins can be shared with user functions, allowing in-sys tem debugging without occupying package pins. each device is specified for 2.7 v-to-3.6 v operation over the industrial temperature range (-40c to +85c). (note that 3.0 v-to-3.6 v is required for usb communication.) the port i/o and /rst pins are tolerant of input signals up to 5 v. c8051f320/1 are available in a 32-pin lqfp or a 28-pin mlp package. table 1.1. product selection guide mips (peak) flash memory ram calibrated internal oscillator usb supply voltage regulator smbus/i 2 c enhanced spi uart timers (16-bit) programmable counter array digital port i/os 10-bit 200ksps adc temperature sensor voltage reference analog comparators package c8051f320 25 16k 2304 3 3 3 3 3 3 4 3 25 3 3 3 2 lqfp-32 C8051F321 25 16k 2304 3 3 3 3 3 3 4 3 21 3 3 3 2 mlp-28
c8051f320/1 18 rev. 1.1 uart 16kbyte flash 256 byte sram por sfr bus 8 0 5 1 c o r e reset /rst/c2ck external oscillator circuit debug hw brown- out p 0 d r v 1k byte xram xtal1 xtal2 p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4 p0.5 p0.6/cnvstr p0.7/vref spi regin c r o s s b a r p 1 d r v p1.0 p1.1 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7 port 0 latch smbus timer 0,1,2,3 / rtc port 1 latch system clock p 2 d r v p 3 d r v p2.0 p2.1 p2.2 p2.3 p2.4 p2.5 p2.6 p2.7 p3.0/c2d 10-bit 200ksps adc a m u x ain0-ain16 vref vdd cp1 + - temp vdd cp0 + - c2d port 2 latch port 3 latch pca/ wdt usb controller usb transceiver analog/digital power voltage regulator 5.0v 1k byte usb sram vbus d+ d- vref 12mhz internal oscillator gnd vdd in out enable vref x4 2 usb clock 2 1,2,3,4 clock recovery figure 1.1. c8051f320 block diagram
c8051f320/1 rev. 1.1 19 uart 16kbyte flash 256 byte sram por sfr bus 8 0 5 1 c o r e reset /rst/c2ck external oscillator circuit debug hw brown- out p 0 d r v 1k byte xram xtal1 xtal2 p0.0 p0.1 p0.2/xtal1 p0.3/xtal2 p0.4 p0.5 p0.6/cnvstr p0.7/vref spi regin c r o s s b a r p 1 d r v p1.0 p1.1 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7 port 0 latch smbus timer 0,1,2,3 / rtc port 1 latch system clock p 2 d r v p 3 d r v p2.0 p2.1 p2.2 p2.3 p3.0/c2d 10-bit 200ksps adc a m u x ain0-ain11 vref vdd cp1 + - temp vdd cp0 + - c2d port 2 latch port 3 latch pca/ wdt usb controller usb transceiver analog/digital power voltage regulator 5.0v 1k byte usb sram vbus d+ d- vref 12mhz internal oscillator gnd vdd in out enable vref x4 2 usb clock 2 1,2,3,4 clock recovery figure 1.2. C8051F321 block diagram
c8051f320/1 20 rev. 1.1 1.1. cip-51? microcontroller core 1.1.1. fully 8051 compatible the c8051f320/1 family utilizes silicon labs' proprietary cip-51 microcontroller core. the cip-51 is fully compat - ible with the mcs-51? instruction set; standard 803x/805 x assemblers and compilers can be used to develop soft - ware. the cip-51 core offers all the peripherals included with a standard 8052, including four 16-bit counter/timers, a full-duplex uart with extended baud rate configuration, an enhanced spi port, 2304 bytes of on-chip ram, 128 byte special function re gister (sfr) address space, and 25/21 i/o pins. 1.1.2. improved throughput the cip-51 employs a pipelined architectur e that greatly increases its instruct ion throughput over the standard 8051 architecture. in a standard 8051, all instructions except for mul and div take 12 or 24 system clock cycles to exe - cute with a maximum sy stem clock of 12-to-24 mhz. by contrast, the ci p-51 core executes 70% of its instructions in one or two system clock cycles, with only four instru ctions taking more than four system clock cycles. the cip-51 has a total of 109 instructions. the table below shows the tota l number of instructions that require each execution time. with the cip-51's maxi mum system clock at 25 mhz, it has a peak throughput of 25 mips. figure 1.3 shows a com - parison of peak throughputs for va rious 8-bit microcontroller cores with their maximum system clocks. clocks to execute 1 2 2/3 3 3/4 4 4/5 5 8 number of instructions 26 50 5 14 7 3 1 2 1 5 10 15 20 aduc812 8051 (16mhz clk) philips 80c51 (33mhz clk) microchip pic17c75x (33mhz clk) silicon labs cip-51 (25mhz clk) mips 25 figure 1.3. comparison of peak mcu execution speeds
c8051f320/1 rev. 1.1 21 1.1.3. additional features the c8051f320/1 soc family includes several key enhancem ents to the cip-51 core and peripherals to improve per - formance and ease of use in end applications. the extended interrupt handler provides 16 interrupt sources into the cip-51 (as opposed to 7 for the standard 8051), allowing numerous analog and digital peripherals to interrupt the controller. an interrupt driven system requires less intervention by the mcu, giving it more effective throughput . the extra interrupt sources are very useful when build - ing multi-tasking, real-time systems. nine reset sources are available: powe r-on reset circuitry (por), an on-chip vdd monitor (forces reset when power supply voltage drops below v rst as given in table 10.1 on page 105 ), the usb controller (usb bus reset or a vbus transition), a watchdog timer, a missing clock detector, a voltage level detection from comparator0, a forced soft - ware reset, an external reset pin, and an errant flash r ead/write protection circuit. each reset source except for the por, reset input pin, or flash error may be disabled by the user in software. the wdt may be permanently enabled in software after a power-on reset during mcu initialization. the internal oscillator is factory calibrated to 12 mhz 1.5%, and the internal oscillator period may be user pro - grammed in ~0.25% increments. a clock recovery mechanism allows the internal oscillator to be used with the 4x clock multiplier as the usb clock sour ce in full speed mode; the internal osci llator can also be used as the usb clock source in low speed mode. external oscillators may also be used with the 4x clock multiplier. an external oscillator drive circuit is also include d, allowing an external crystal, ceram ic resonator, capacitor, rc, or cmos clock source to generate the system clock. the system clock may be configured to use the internal oscillator, external oscillator, or the clock multiplier output divided by 2. if desired, the system clock sour ce may be switched on-the-fly between oscillator sources. an external oscillator can be extremely useful in low power applications, allowing the mcu to run from a slow (power saving) external clock source, whil e periodically switching to the internal oscillator as needed. pca wdt missing clock detector (one- shot) software reset (swrsf) system reset reset funnel px.x px.x en system clock cip-51 microcontroller core extended interrupt handler clock select en wdt enable mcd enable errant flash operation + - comparator 0 c0rsef /rst (wired-or) power on reset + - vdd supply monitor enable '0' internal oscillator xtal1 xtal2 external oscillator drive clock multiplier usb controller vbus transition enable figure 1.4. on-chip clock and reset
c8051f320/1 22 rev. 1.1 1.2. on-chip memory the cip-51 has a standard 8051 program and data address conf iguration. it includes 256 bytes of data ram, with the upper 128 bytes dual-mapped. indirect addressing accesses the uppe r 128 bytes of general purpose ram, and direct addressing accesses the 128 byte sfr address space. the lowe r 128 bytes of ram are acce ssible via direct and indi - rect addressing. the first 32 bytes are addressable as four banks of general purpose registers, and the next 16 bytes can be byte addressable or bit addressable. program memory consists of 16k bytes of flash. this memory may be reprogrammed in-system in 512 byte sec - tors, and requires no special off-chip programming voltage. see figure 1.5 for the mcu system memory map. figure 1.5. on-board memory map program/data memory (flash) (direct and indirect addressing) 0x00 0x7f upper 128 ram (indirect addressing only) 0x80 0xff special function register's (direct addressing only) data memory (ram) general purpose registers 0x1f 0x20 0x2f bit addressable lower 128 ram (direct and indirect addressing) 0x30 internal data address space external data address space xram - 1024 bytes (accessable using movx instruction) 0x0000 0x03ff same 2048 bytes as from 0x0000 to 0x07ff, wrapped on 2k-byte boundaries 0x0400 0xffff 16k flash (in-system programmable in 512 byte sectors) 0x0000 reserved 0x3e00 0x3dff usb fifos 1024 bytes 0x07ff 0x0800
c8051f320/1 rev. 1.1 23 1.3. universal serial bus controller the universal serial bus controller (usb 0) is a usb 2.0 compliant full or low speed function with integrated transceiver and endpoint fifo ram. a total of eight endpoi nt pipes are available: a bi-directional control endpoint (endpoint0) and three pairs of in/o ut endpoints (endpoints1-3 in/out). a 1k block of xram is used as dedicated usb fifo sp ace. this fifo space is distributed among endpoints0-3; endpoint1-3 fifo slots can be configured as in, out, or both in and out (split mode). the maximum fifo size is 512 bytes (endpoint3). usb0 can be operated as a full or low speed function. on-chip 4x clock multiplier and clock recovery circuitry allow both full and low speed options to be implemented with the on-chip precision os cillator as the usb clock source. an external oscillator source can also be used w ith the 4x clock multiplier to generate the usb clock. the cpu clock source is independent of the usb clock. the usb transceiver is usb 2.0 compliant, and includes on -chip matching and pull-up resistors. the pull-up resis - tors can be enabled/disabled in softwa re, and will appear on the d+ or d- pin according to the software-selected speed setting (full or low speed). 1.4. voltage regulator c8051f320/1 devices include a 5 v-to-3 v voltage regulator (reg0). when enabled, the reg0 output appears on the vdd pin and can be used to power external de vices. reg0 can be enable d/disabled by software. transceiver serial interface engine (sie) usb fifos (1k ram) d+ d- vdd endpoint0 in/out endpoint1 in out endpoint2 in out endpoint3 in out data transfer control cip-51 core usb control, status, and interrupt registers figure 1.6. usb controller block diagram
c8051f320/1 24 rev. 1.1 1.5. on-chip debug circuitry the c8051f320/1 devices include on-chip silicon labs 2-wire (c2) debug circuitry that provides non-intrusive, full speed, in-circuit debugging of the production part installed in the end application. silicon labs' debugging system supports inspection and modi fication of memory and registers, breakpoints, and sin - gle stepping. no additional target ram, program memory, timers, or communications channels are required. all the digital and analog peripherals are functional and work correct ly while debugging. all the peripherals (except for the usb, adc, and smbus) are stalled when the mcu is halted, during single stepping, or at a breakpoint in order to keep them synchronized. the c8051f310dk development kit provides all the hardware and software necessary to develop application code and perform in-circuit debugging with the c8051f320/1 mcus. the kit includes software with a developer's studio and debugger, an integrated 8051 assembler, and an rs-232 to c2 serial adapter. it also has a target application board with the associated mcu installed a nd prototyping area, plus the rs-232 and c2 cables, and wall-mount power sup - ply. the development kit requires a windows 95/98/nt/me/2000 computer with one available rs-232 serial port. as shown in figure 1.7 , the pc is connected via rs-232 to the serial adapter. a six-inch ri bbon cable connects the serial adapter to the user's applica tion board, picking up the two c2 pins and vdd and gnd. the serial adapter takes its power from the application board. for applications where there is not sufficient power available from the tar - get board, the provided power supply can be connected directly to the serial adapter. the silicon labs ide interface is a vastly superior deve loping and debugging configuration, compared to standard mcu emulators that use on-board "ice chips" and require the mcu in the app lication board to be socketed. silicon labs' debug paradigm increases ease of use and preserve s the performance of the precision analog peripherals. target pcb rs-232 serial adapter vdd gnd c2 (x2), vdd, gnd windows 95/98/nt/me/2000 silicon labs integrated development environment c8051f320 figure 1.7. development/in-system debug diagram
c8051f320/1 rev. 1.1 25 1.6. programmable digital i/o and crossbar c8051f320 devices include 25 i/o pins (three byte-wide po rts and one 1-bit-wide port); C8051F321 devices include 21 i/o pins (two byte-wide ports, one 4-bit-wide port, and one 1-bit-wide port). the c8051f320/1 ports behave like typical 8051 ports with a few enhancements. each port pin may be configured as an analog input or a digital i/o pin. pins selected as digital i/os may additionally be config ured for push-pull or open-drain output. the ?weak pull-ups? that are fixed on typical 8051 devices may be globally disabled, providing power savings capabilities. the digital crossbar allows mapping of internal digital system resources to port i/o pins (see figure 1.8 ). on-chip counter/timers, serial buses, hw interrupts, comparator outp uts, and other digital signals in the controller can be con - figured to appear on the port i/o pins specified in the crossbar control register s. this allows the user to select the exact mix of general purpose port i/o and digital resources needed for the particular application. 1.7. serial ports the c8051f320/1 family includes an smbus/i 2 c interface, a full-duplex uart with enhanced baud rate configura - tion, and an enhanced spi interface. each of the serial buses is fully implem ented in hardware and makes extensive use of the cip-51's interrupts, thus requiring very little cpu intervention. figure 1.8. digital crossbar diagram xbr0, xbr1, pnskip registers digital crossbar priority decoder 2 p0 i/o cells p0.0 p0.7 8 pnmdout, pnmdin registers uart (internal digital signals) highest priority lowest priority sysclk 2 smbus t0, t1 2 6 pca cp1 outputs 2 4 spi cp0 outputs 2 p1 i/o cells p1.0 p1.7 8 p2 i/o cells p2.0 p2.7 8 p3 i/o cells p3.0 1 (port latches) p0 (p0.0-p0.7) (p1.0-p1.7) (p2.0-p2.7) (p3.0) 8 8 8 8 p1 p2 p3 note: p2.4-p2.7 only available on the c8051f320
c8051f320/1 26 rev. 1.1 1.8. programmable counter array an on-chip programmable counter/timer array (pca) is included in addition to the four 16-bit general purpose counter/timers. the pca consists of a dedicated 16-bit c ounter/timer time base with five programmable capture/com - pare modules. the pca clock is derived from one of six sources: the system clock divided by 12, the system clock divided by 4, timer 0 overflows, an external clock input (e ci), the system clock, or th e external oscillator clock source divided by 8. the external clock source selection is useful for real-time clock f unctionality, where the pca is clocked by an external source while the intern al oscillator drives the system clock. each capture/compare module can be conf igured to operate in one of six modes: edge-triggered capture, software timer, high speed output, 8- or 16-bit pulse width modulator, or frequency output. additionally, capture/compare module 4 offers watchdog timer (wdt) capabilities. followin g a system reset, module 4 is configured and enabled in wdt mode. the pca capture/compare module i/o and external clock input may be routed to port i/o via the digital crossbar. figure 1.9. pca block diagram capture/compare module 1 capture/compare module 0 capture/compare module 2 capture/compare module 3 capture/compare module 4 / wdt cex1 eci crossbar cex2 cex3 cex4 cex0 port i/o 16-bit counter/timer pca clock mux sysclk/12 sysclk/4 timer 0 overflow eci sysclk external clock/8
c8051f320/1 rev. 1.1 27 1.9. 10-bit analog to digital converter the c8051f320/1 devices include an on-chip 10-bit sar adc with a 17-channel differential input multiplexer. with a maximum throughput of 200 ksps, the adc offers true 10-bit linearity with an inl of 1lsb. the adc system includes a configurable analog multiplexe r that selects both positive and negative adc inputs. ports1-3 are available as adc inputs; additionally, the on-chip temperature sens or output and the power s upply voltage (vdd) are avail - able as adc inputs. user firmware may shut down the adc to save power. conversions can be started in six ways: a software command, an overflow of timer 0, 1, 2, or 3, or an external con - vert start signal. this flexibility allows the start of convers ion to be triggered by software events, a periodic signal (timer overflows), or external hw signa ls. conversion completions are indicated by a status bit and an interrupt (if enabled). the resulting 10-bit data word is latched in to the adc data sfrs upon completion of a conversion. window compare registers for the adc data can be configured to interrupt the controller when adc data is either within or outside of a specified range. the adc can monitor a key voltage continuously in background mode, but not interrupt the controller unless the converted data is within /outside the specified range. 10-bit sar adc timer 1 overflow cnvstr input timer 3 overflow (+) (-) configuration, control, and data registers 19-to-1 amux 19-to-1 amux p1.0 p1.7 p2.0 p2.7 p1.0 p1.7 p2.0 p2.7 p3.0 p3.0 p2.4-2.7 available on c8051f320 p2.4-2.7 available on c8051f320 analog multiplexer timer 0 overflow timer 2 overflow start conversion 000 ad0busy (w) 001 010 011 100 101 16 window compare logic window compare interrupt adc data registers end of conversion interrupt vdd temp sensor vref gnd figure 1.10. 10-bit adc block diagram
c8051f320/1 28 rev. 1.1 1.10. comparators c8051f320/1 devices include two on-chip voltage comparator s that are enabled/disabled and configured via user software. port i/o pins may be config ured as comparator inputs via a selec tion mux. two comparator outputs may be routed to a port pin if desired: a latched output and/or an unlatched (asynchronous) output. comparator response time is programmable, allowing the user to select between high-speed and low-power modes. positive and negative hyster - esis are also configurable. comparator interrupts may be generated on rising, falling, or both edges. when in idle mode, these interrupts may be used as a ?wake-up? source. comparator0 may also be co nfigured as a reset source. figure 1.11 shows the comparator0 block diagram. figure 1.11. comparator0 block diagram vdd cpt0cn reset decision tree + - crossbar interrupt logic q q set clr d q q set clr d (synchronizer) gnd cp0 + p1.0 p1.4 p2.0 p2.4 cp0 - p1.1 p1.5 p2.1 p2.5 cp0en cp0out cp0rif cp0fif cp0hyp1 cp0hyp0 cp0hyn1 cp0hyn0 cpt0mx cmx0n1 cmx0n0 cmx0p1 cmx0p0 cpt0md cp0rie cp0fie cp0md1 cp0md0 cp0 cp0a cp0 rising-edge cp0 falling-edge cp0 interrupt cp0rie cp0fie note: p2.4 and p2.5 available only on c8051f320
c8051f320/1 rev. 1.1 29 2. absolute ma ximum ratings table 2.1. absolute maximum ratings * parameter conditions min typ max units ambient temperature under bias -55 125 c storage temperature -65 150 c voltage on any port i/o pin or /rst with respect to gnd -0.3 5.8 v voltage on vdd with respect to gnd -0.3 4.2 v maximum total current through vdd and gnd 500 ma maximum output current sunk by /rst or any port pin 100 ma * note: stresses above those listed under ?absolute maximu m ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the devices at those or any other conditions above those indi- cated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
c8051f320/1 30 rev. 1.1 3. global dc electrical characteristics table 3.1. global dc electrical characteristics -40c to +85c, 25 mhz system clock unless otherwise specified. parameter conditions min typ max units digital supply voltage (note 1) 2.7 3.3 3.6 v digital supply current with cpu active vdd=3.3v, clock=24mhz vdd=3.3v, clock=1mhz vdd=3.3v, clock=32khz 10 0.6 30 ma ma a digital supply current with cpu active and usb active (full or low speed) vdd=3.3v, clock=24mhz vdd=3.3v, clock=6mhz tbd tbd ma ma digital supply current with cpu inactive (not accessing flash) vdd=3.3v, clock=24mhz vdd=3.3v, clock=1mhz vdd=3.3v, clock=32khz 5 0.3 14 ma ma a digital supply current (suspend mode or shutdown mode) oscillator not running < 0.1 a digital supply ram data reten- tion voltage 1.5 v sysclk (system clock) (note 2) 0 25 mhz t sysh (sysclk high time) 18 ns t sysl (sysclk low time) 18 ns specified operating temperature range -40 +85 c note 1: usb requires 3.0 v minimum supply voltage. note 2: sysclk must be at least 32 khz to enable debugging.
c8051f320/1 rev. 1.1 31 4. pinout and package definitions table 4.1. pin definitions for the c8051f320/1 name pin numbers type description ?f320 ?f321 vdd 6 6 power in power out 2.7-3.6 v power supply voltage input. 3.3 v voltage regulator output. see section 8 . gnd 3 3 ground. /rst/ c2ck 9 9 d i/o d i/o device reset. open-drain output of internal por or vdd moni - tor. an external source can initiate a system reset by driving this pin low for at least 15 s. see section 10 . clock signal for the c2 debug interface. p3.0/ c2d 10 10 d i/o d i/o port 3.0. see section 14 for a complete description. bi-directional data signal for the c2 debug interface. regin 7 7 power in 5 v regulator input. this pin is the input to the on-chip voltage regulator. vbus 8 8 d in vbus sense input. this pin should be connected to the vbus signal of a usb network. a 5 v signal on this pin indicates a usb network connection. d+ 4 4 d i/o usb d+. d- 5 5 d i/o usb d-. p0.0 2 2 d i/o port 0.0. see section 14 for a complete description. p0.1 1 1 d i/o port 0.1. see section 14 for a complete description. p0.2/ xtal1 32 28 d i/o a in port 0.2. see section 14 for a complete description. external clock input. this pin is the external oscillator return for a crystal or resonator. see section 13 . p0.3/ xtal2 31 27 d i/o a i/o or d in port 0.3. see section 14 for a complete description. external clock output. this pin is the excitation driver for an external crystal or resonator, or an external clock input for cmos, capacitor, or rc oscilla tor configurations. see section 13 . p0.4 30 26 d i/o port 0.4. see section 14 for a complete description. p0.5 29 25 d i/o port 0.5. see section 14 for a complete description.
c8051f320/1 32 rev. 1.1 p0.6/ cnvstr 28 24 port 0.6. see section 14 for a complete description. adc0 external convert start input. see section 5 . p0.7/ vref 27 23 d i/o a i/o port 0.7. see section 14 for a complete description. external vref input or output. see section 6 . p1.0 26 22 d i/o or a in port 1.0. see section 14 for a complete description. p1.1 25 21 d i/o or a in port 1.1. see section 14 for a complete description. p1.2 24 20 d i/o or a in port 1.2. see section 14 for a complete description. p1.3 23 19 d i/o or a in port 1.3. see section 14 for a complete description. p1.4 22 18 d i/o or a in port 1.4. see section 14 for a complete description. p1.5 21 17 d i/o or a in port 1.5. see section 14 for a complete description. p1.6 20 16 d i/o or a in port 1.6. see section 14 for a complete description. p1.7 19 15 d i/o or a in port 1.7. see section 14 for a complete description. p2.0 18 14 d i/o or a in port 2.0. see section 14 for a complete description. p2.1 17 13 d i/o or a in port 2.1. see section 14 for a complete description. p2.2 16 12 d i/o or a in port 2.2. see section 14 for a complete description. p2.3 15 11 d i/o or a in port 2.3. see section 14 for a complete description. p2.4 14 d i/o or a in port 2.4. see section 14 for a complete description. p2.5 13 d i/o or a in port 2.5. see section 14 for a complete description. p2.6 12 d i/o or a in port 2.6. see section 14 for a complete description. table 4.1. pin definiti ons for the c8051f320/1 name pin numbers type description ?f320 ?f321
c8051f320/1 rev. 1.1 33 p2.7 11 d i/o or a in port 2.7. see section 14 for a complete description. table 4.1. pin definiti ons for the c8051f320/1 name pin numbers type description ?f320 ?f321 1 vbus p1.2 p1.7 p1.4 p1.3 p1.5 d+ d- gnd p0.1 p0.0 p2.0 p2.1 2 3 4 5 6 7 8 24 23 22 21 20 19 18 17 9 10 11 12 13 14 15 16 32 31 30 29 28 27 26 25 p1.6 c8051f320 top view vdd regin /rst / c2ck p3.0 / c2d p2.7 p2.6 p2.5 p2.4 p2.3 p2.2 p1.1 p1.0 p0.7 p0.6 p0.5 p0.4 p0.3 p0.2 figure 4.1. lqfp-32 pinout diagram (top view)
c8051f320/1 34 rev. 1.1 pin 1 identifier a1 e b 1 32 e1 d1 d e a2 a figure 4.2. lqfp-32 package diagram table 4.2. lqfp-32 package dimensions mm min typ max a- -1.60 a1 0.05 - 0.15 a2 1.35 1.40 1.45 b 0.30 0.37 0.45 d-9.00- d1 - 7.00 - e-0.80- e-9.00- e1 - 7.00 -
c8051f320/1 rev. 1.1 35 4 5 6 7 2 1 3 11 12 13 14 9 8 10 18 17 16 15 20 21 19 25 26 27 28 23 22 24 C8051F321 top view p0.1 p0.0 gnd d+ d- vdd regin vbus /rst / c2ck p3.0 / c2d p2.3 p2.2 p2.1 p2.0 p1.7 p1.6 p1.5 p1.4 p1.3 p1.2 p1.1 p1.0 p0.7 p0.6 p0.5 p0.4 p0.3 p0.2 gnd gnd figure 4.3. mlp-28 pinout diagram (top view)
c8051f320/1 36 rev. 1.1 1 e d a2 a a1 e a3 e2 r e l bottom view side view 2 3 4 5 6 7 8 9 10 12 13 14 21 20 19 17 16 15 28 27 26 24 23 22 e2 25 2 d2 11 18 d2 2 6 x e 6 x e detail 1 detail 1 aa bb cc dd b figure 4.4. mlp-28 package drawing table 4.2. mlp-28 package dimensions mm min typ max a 0.80 0.90 1.00 a1 0 0.02 0.05 a2 0 0.65 1.00 a3 - 0.25 - b 0.18 0.23 0.30 d-5.00- d2 2.90 3.15 3.35 e-5.00- e2 2.90 3.15 3.35 e-0.5- l 0.45 0.55 0.65 n-28- nd - 7 - ne - 7 - r0.09 - - aa - 0.435 - bb - 0.435 - cc - 0.18 - dd - 0.18 -
c8051f320/1 rev. 1.1 37 optional gnd connection b l 0.50 mm 0.30 mm 0.10 mm 0.20 mm 0.85 mm 0.35 mm e e d 0.50 mm 0.30 mm 0.10 mm 0.20 mm 0.85 mm 0.35 mm top view e2 d2 0.20 mm 0.20 mm 0.50 mm 0.50 mm figure 4.5. typical mlp-28 landing diagram
c8051f320/1 38 rev. 1.1 b l 0.50 mm 0.30 mm 0.10 mm 0.20 mm 0.85 mm 0.35 mm e e d 0.50 mm 0.30 mm 0.10 mm 0.20 mm 0.85 mm 0.35 mm top view e2 d2 0.20 mm 0.20 mm 0.50 mm 0.50 mm 0.30 mm 0.20 mm 0.60 mm 0.40 mm 0.70 mm 0.60 mm figure 4.6. typical mlp-28 solder mask
c8051f320/1 rev. 1.1 39 5. 10-bit adc (adc0) the adc0 subsystem for the c8051f320/1 consists of two an alog multiplexers (referred to collectively as amux0) with 17 total input selections, and a 200 ksps, 10-bit successive-approximation-register adc with integrated track- and-hold and programmable window detector. the amux0, data conversion modes, and window detector are all configurable under software control via the special function registers shown in figure 5.1 . adc0 operates in both single-ended and differential modes, an d may be configured to measure p1.0-p3.0, the temperature sensor output, or vdd with respect to p1.0-p3.0, vref, or gnd. the ad c0 subsystem is enabled only when the ad0en bit in the adc0 control register (adc 0cn) is set to logic 1. the adc0 subsystem is in low power shutdown when this bit is logic 0. adc0cf ad0ljst ad0sc0 ad0sc1 ad0sc2 ad0sc3 ad0sc4 10-bit sar adc ref sysclk adc0h 32 adc0cn ad0cm0 ad0cm1 ad0cm2 ad0wint ad0busy ad0int ad0tm ad0en timer 0 overflow timer 2 overflow timer 1 overflow start conversion 000 ad0busy (w) vdd adc0lth 19-to-1 amux ad0wint 001 010 011 100 cnvstr input window compare logic gnd p1.0 p1.7 p2.0 p2.7 p3.0 101 timer 3 overflow adc0ltl adc0gth adc0gtl adc0l amx0p amx0p4 amx0p3 amx0p2 amx0p1 amx0p0 amx0n amx0n4 amx0n3 amx0n2 amx0n1 amx0n0 (+) (-) vref p2.4-2.7 available on c8051f320 temp sensor 19-to-1 amux p1.0 p1.7 p2.0 p2.7 p3.0 p2.4-2.7 available on c8051f320 vdd figure 5.1. adc0 functional block diagram
c8051f320/1 40 rev. 1.1 5.1. analog multiplexer amux0 selects the positive and negative inputs to the adc. any of the following may be selected as the positive input: p1.0-p3.0, the on-chip temperature sensor, or the positive power supply (vdd). any of the following may be selected as the negative input: p1.0-p3.0, vref, or gnd. when gnd is selected as the negative input, adc0 operates in single-ended mode; all other ti mes, adc0 operates in differential mode. the adc0 input channels are selected in the amx0p and am x0n registers as described in figure 5.5 and figure 5.6 . the conversion code format differs be tween single-ended and differential m odes. the registers adc0h and adc0l contain the high and lo w bytes of the output conversion code from the adc at the completio n of each conversion. data can be right-justified or left-justified, depending on the setting of the ad0ljst bit (adc0cn.0). when in sin - gle-ended mode, conversion codes are represented as 10-b it unsigned integers. inputs are measured from ?0? to vref * 1023/1024. example codes are shown below for both righ t-justified and left-justified data. unused bits in the adc0h and adc0l registers are set to ?0?. when in differential mode, conversion codes are represented as 10-bit signed 2?s complement numbers. inputs are measured from -vref to vref * 511/5 12. example codes are shown below for both right-justified and left-justified data. for right-justified data, the unused msbs of adc0h are a sign-extension of the da ta word. for left-justified data, the unused lsbs in the adc0l register are set to ?0?. important note about adc0 input configuration: port pins selected as adc0 i nputs should be configured as analog inputs, and should be skipped by the digital crossbar. to configure a port pin for analog input, set to ?0? the corresponding bit in register pnmdin (for n = 0,1,2,3). to fo rce the crossbar to skip a po rt pin, set to ?1? the corre - sponding bit in register pnskip (for n = 0,1,2). see section ?14. port input/output? on page 127 for more port i/o configuration details. input voltage (single-ended) right-justified adc0h:adc0l (ad0ljst = 0) left-justified adc0h:adc0l (ad0ljst = 1) vref * 1023/1024 0x03ff 0xffc0 vref * 512/1024 0x0200 0x8000 vref * 256/1024 0x0100 0x4000 0 0x0000 0x0000 input voltage (differential) right-justified adc0h:adc0l (ad0ljst = 0) left-justified adc0h:adc0l (ad0ljst = 1) vref * 511/512 0x01ff 0x7fc0 vref * 256/512 0x0100 0x4000 0 0x0000 0x0000 -vref * 256/512 0xff00 0xc000 - vref 0xfe00 0x8000
c8051f320/1 rev. 1.1 41 5.2. temperature sensor the typical temperature sensor transfer function is shown in figure 5.2 . the output voltage (v temp ) is the positive adc input when the temperature sensor is sel ected by bits amx0p4-0 in register amx0p. note that parameters which affect adc measurement, in particular the volt age reference value, will also affect temperature measurement. figure 5.2. typical temperature sensor transfer function 0 -50 50 100 (celsius) 500 600 700 800 900 (mv) v temp = 2.86(temp c ) + 776 mv 1000
c8051f320/1 42 rev. 1.1 5.3. modes of operation adc0 has a maximum conversion speed of 200 ksps. the adc0 conversion clock is a divided version of the system clock, determined by the ad0sc bits in the adc0cf register (system clock divided by (ad0sc + 1) for 0 ad0sc 31). 5.3.1. starting a conversion a conversion can be initiated in one of five ways, dependi ng on the programmed states of the adc0 start of conver - sion mode bits (ad0cm2-0) in register adc0cn. conv ersions may be initiated by one of the following: 1. writing a ?1? to the ad0busy bit of register adc0cn 2. a timer 0 overflow (i.e., timed continuous conversions) 3. a timer 2 overflow 4. a timer 1 overflow 5. a rising edge on the cnvstr input signal (pin p0.6) 6. a timer 3 overflow writing a ?1? to ad0busy provides software control of adc0 whereby conversions are performed "on-demand". during conversion, the ad0busy bit is set to logic 1 and reset to logic 0 when the conversion is complete. the fall - ing edge of ad0busy triggers an interrupt (when enabled) and sets the adc0 interrupt flag (ad0int). note: when polling for adc conversion completions, the adc0 interrupt fl ag (ad0int) should be used. converted data is avail - able in the adc0 data registers, adc0h:adc0l, when bit ad 0int is logic 1. note that when timer 2 or timer 3 overflows are used as the conversion sour ce, low byte overflows are used if timer 2/3 is in 8-bit mode; high byte overflows are used if timer 2/3 is in 16-bit mode. see section ?19. timers? on page 217 for timer configuration. important note about using cnvstr: the cnvstr input pin also functions as port pin p0.6. when the cnvstr input is used as the adc0 conv ersion source, port pin p0.6 should be skipped by the digital crossbar. to configure the crossbar to skip p0.6, set to ?1? bit6 in register p0skip. see section ?14. port input/output? on page 127 for details on port i/o configuration.
c8051f320/1 rev. 1.1 43 5.3.2. tracking modes the ad0tm bit in register adc0cn controls the adc0 track-and-hold mode. in its default state, the adc0 input is continuously tracked, except wh en a conversion is in progr ess. when the ad0tm bit is logic 1, adc0 operates in low-power track-and-hold mode. in this mode, each conversion is preceded by a tracking period of 3 sar clocks (after the start-of-conversion signal). when the cnvstr signal is used to initiate conversions in low-power tracking mode, adc0 tracks only when cnvstr is low; c onversion begins on the rising edge of cnvstr (see figure 5.3 ). tracking can also be disabled (shutdown) when the device is in low power standby or sleep modes. low-power track- and-hold mode is also useful when amux settings are fr equently changed, due to the settling time requirements described in section ?5.3.3. settling time requirements? on page 44 . figure 5.3. 10-bit adc track and conversion example timing write '1' to ad0busy, timer 0, timer 2, timer 1, timer 3 overflow (ad0cm[2:0]=000, 001,010 011, 101) ad0tm=1 track convert low power mode ad0tm=0 track or convert convert track low power or convert sar clocks 123456789101112 123456789 sar clocks b. adc0 timing for internal trigger source 123456789 cnvstr (ad0cm[2:0]=100) ad0tm=1 a. adc0 timing for external trigger source sar clocks track or convert convert track ad0tm=0 track convert low power mode low power or convert 10 11 13 14 10 11
c8051f320/1 44 rev. 1.1 5.3.3. settling time requirements when the adc0 input configuration is changed (i.e., a different amux0 selection is made), a minimum tracking time is required before an accurate conversion can be pe rformed. this tracking time is determined by the amux0 resistance, the adc0 sampling capacitance, any external source resistance, and the accu racy required for the conver - sion. note that in low-power tracking mode, three sar clocks are used for tracking at th e start of every conversion. for most applications, these thr ee sar clocks will meet the mini mum tracking time requirements. figure 5.4 shows the equivalent adc0 input circuits for both differential and single-end ed modes. notice that the equivalent time constant for both input circuits is the same. the required adc0 settling time for a given settling accuracy (sa) may be approximated by equation 5.1 . when measuring the temperatur e sensor output or vdd with respect to gnd, r total reduces to r mux . see table 5.1 for adc0 minimum settling time requirements. where: sa is the settling accuracy, given as a fraction of an ls b (for example, 0.25 to settle within 1/4 lsb) t is the required settling time in seconds r total is the sum of the amux0 resistance and any external source resistance. n is the adc resolution in bits (10). equation 5.1. adc0 settling time requirements t 2 n sa ------ - ?? ?? r total c sample ln = r mux = 5k rc input = r mux * c sample r mux = 5k c sample = 5pf c sample = 5pf mux select mux select differential mode px.x px.x r mux = 5k c sample = 5pf rc input = r mux * c sample mux select single-ended mode px.x figure 5.4. adc0 equivalent input circuits
c8051f320/1 rev. 1.1 45 figure 5.5. amx0p: amux0 posi tive channel select register bits7-5: unused. read = 000b; write = don?t care. bits4-0: amx0p4-0: amux0 positive input selection ?only applies to c8051f320; selection reserved on C8051F321 devices. r r r r/w r/w r/w r/w r/w reset value - - - amx0p4 amx0p3 amx0p2 amx0p1 amx0p0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xbb amx0p4-0 adc0 po sitive input 00000 p1.0 00001 p1.1 00010 p1.2 00011 p1.3 00100 p1.4 00101 p1.5 00110 p1.6 00111 p1.7 01000 p2.0 01001 p2.1 01010 p2.2 01011 p2.3 01100? p2.4? 01101? p2.5? 01110? p2.6? 01111? p2.7? 10000 p3.0 10001 - 11101 reserved 11110 temp sensor 11111 vdd
c8051f320/1 46 rev. 1.1 figure 5.6. amx0n: amux0 ne gative channel select register bits7-5: unused. read = 000b; write = don?t care. bits4-0: amx0n4-0: amux0 negative input selection. note that when gnd is selected as the negative input, adc0 operates in single-ended mode. for all other negative input selections, adc0 operates in differential mode. ?only applies to c8051f320; selection reserved on C8051F321 devices. r r r r/w r/w r/w r/w r/w reset value - - - amx0n4 amx0n3 amx0n2 amx0n1 amx0n0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xba amx0n4-0 adc0 negative input 00000 p1.0 00001 p1.1 00010 p1.2 00011 p1.3 00100 p1.4 00101 p1.5 00110 p1.6 00111 p1.7 01000 p2.0 01001 p2.1 01010 p2.2 01011 p2.3 01100? p2.4? 01101? p2.5? 01110? p2.6? 01111? p2.7? 10000 p3.0 10001 - 11101 reserved 11110 vref 11111 gnd (adc in single-ended mode)
c8051f320/1 rev. 1.1 47 figure 5.7. adc0cf: adc0 configuration register bits7-3: ad0sc4-0: adc0 sar conversion clock period bits. sar conversion clock is derived from system clock by the following equation, where ad0sc refers to the 5-bit value held in bits ad0sc4-0. sar conversion clock requirements are given in table 5.1. bit2: ad0ljst: adc0 left justify select. 0: data in adc0h:adc0l registers are right-justified. 1: data in adc0h:adc0l re gisters are left-justified. bits1-0: unused. read = 00b; write = don?t care. r/w r/w r/w r/w r/w r/w r/w r/w reset value ad0sc4 ad0sc3 ad0sc2 ad0sc1 ad0sc0 ad0ljst - - 11111000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xbc ad0sc sysclk clk sar --------------------- -1 ? = figure 5.8. adc0h: adc0 data word msb register bits7-0: adc0 data word high-order bits. for ad0ljst = 0: bits 7-2 are the sign extension of bit1. bits 1-0 are the upper 2 bits of the 10-bit adc0 data word. for ad0ljst = 1: bits 7-0 are the most-significant bits of the 10-bit adc0 data word. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xbe
c8051f320/1 48 rev. 1.1 figure 5.9. adc0l: adc0 data word lsb register bits7-0: adc0 data word low-order bits. for ad0ljst = 0: bits 7-0 are the lower 8 bits of the 10-bit data word. for ad0ljst = 1: bits 7-6 are the lower 2 bits of th e 10-bit data word. bits 5-0 will always read ?0?. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xbd
c8051f320/1 rev. 1.1 49 figure 5.10. adc0cn: adc0 control register bit7: ad0en: adc0 enable bit. 0: adc0 disabled. adc0 is in low-power shutdown. 1: adc0 enabled. adc0 is active and ready for data conversions. bit6: ad0tm: adc0 track mode bit. 0: normal track mode: when adc0 is enabled, tracking is continuous unless a conversion is in progress. 1: low-power track mode: tracking defined by ad0cm2-0 bits (see below). bit5: ad0int: adc0 conversion complete interrupt flag. 0: adc0 has not completed a data conversi on since the last time ad0int was cleared. 1: adc0 has completed a data conversion. bit4: ad0busy: adc0 busy bit. read: 0: adc0 conversion is complete or a conversion is not currently in progress. ad0int is set to logic 1 on the falling edge of ad0busy. 1: adc0 conversion is in progress. write: 0: no effect. 1: initiates adc0 conversion if ad0cm2-0 = 000b bit3: ad0wint: adc0 window compare interrupt flag. 0: adc0 window comparison data match has not occurred since this flag was last cleared. 1: adc0 window comparison data match has occurred. bits2-0: ad0cm2-0: adc0 start of conversion mode select. when ad0tm = 0: 000: adc0 conversion initiated on every write of ?1? to ad0busy. 001: adc0 conversion initiated on overflow of timer 0. 010: adc0 conversion initiated on overflow of timer 2. 011: adc0 conversion initiated on overflow of timer 1. 100: adc0 conversion initiated on rising edge of external cnvstr. 101: adc0 conversion initiated on overflow of timer 3. 11x: reserved. when ad0tm = 1: 000: tracking initiated on write of ?1? to ad0busy and lasts 3 sar clocks, followed by conversion. 001: tracking initiated on overflow of timer 0 and lasts 3 sar clocks, followed by conversion. 010: tracking initiated on overflow of timer 2 and lasts 3 sar clocks, followed by conversion. 011: tracking initiated on overflow of timer 1 and lasts 3 sar clocks, followed by conversion. 100: adc0 tracks only when cnvstr input is logic low; conversion starts on rising cnvstr edge. 101: tracking initiated on overflow of timer 3 and lasts 3 sar clocks, followed by conversion. 11x: reserved. r/w r/w r/w r/w r/w r/w r/w r/w reset value ad0en ad0tm ad0int ad0busy ad0wint ad0cm2 ad0cm1 ad0cm0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xe8
c8051f320/1 50 rev. 1.1 5.4. programmable window detector the adc programmable window detector continuously compar es the adc0 conversion results to user-programmed limits, and notifies the system when a desired condition is det ected. this is especially effective in an interrupt-driven system, saving code space and cpu bandwidth while deliver ing faster system response times. the window detector interrupt flag (ad0wint in regist er adc0cn) can also be used in polled mode. the adc0 greater-than (adc0gth, adc0gtl) and less-than (adc0lth, adc0ltl) registers hold the comparison values. the window detector flag can be programmed to indi cate when measured data is inside or outside of the user-programmed limits, depending on the contents of the adc0 less-than and adc0 greater-than registers. the window detector registers must be written with the same format (left/right justified, signed/unsigned) as that of the current adc configuration (left/right justified, single-ended/differential). figure 5.11. adc0gth: adc0 greate r-than data high byte register bits7-0: high byte of adc0 greater-than data word. r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc4 figure 5.12. adc0gtl: adc0 greate r-than data low byte register bits7-0: low byte of adc0 greater-than data word. r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc3
c8051f320/1 rev. 1.1 51 figure 5.13. adc0lth: adc0 less-th an data high byte register bits7-0: high byte of adc0 less-than data word. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc6 figure 5.14. adc0ltl: adc0 less-than data low byte register bits7-0: low byte of adc0 less-than data word. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc5
c8051f320/1 52 rev. 1.1 5.4.1. window detector in single-ended mode figure 5.15 shows two example window comparisons for right-justified, single-ended data, with adc0lth:adc0ltl = 0x0080 (128d) and adc0gth:adc0gtl = 0x0040 (64d). in single-ended mode, the input voltage can range from ?0? to vref * (1023/1024) with resp ect to gnd, and is represented by a 10-bit unsigned inte - ger value. in the left example, an ad0wint interrupt will be generated if the adc0 conversion word (adc0h:adc0l) is within the range defined by adc0gth:adc0gtl and adc0lth:adc0ltl (if 0x0040 < adc0h:adc0l < 0x0080). in the right example, and ad0wint interrupt will be generated if the adc0 conversion word is outside of the rang e defined by the adc0gt and adc0lt registers (if adc0h:adc0l < 0x0040 or adc0h:adc0l > 0x0080). figure 5.16 shows an example usin g left-justified data with equivalent adc0gt and adc0lt register settings.. 0x03ff 0x0081 0x0080 0x007f 0x0041 0x0040 0x003f 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl 0x03ff 0x0081 0x0080 0x007f 0x0041 0x0040 0x003f 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint not affected ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0gth:adc0gtl adc0lth:adc0ltl figure 5.15. adc wi ndow compare example: right- justified single-ended data 0xffc0 0x2040 0x2000 0x1fc0 0x1040 0x1000 0x0fc0 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl 0xffc0 0x2040 0x2000 0x1fc0 0x1040 0x1000 0x0fc0 0x0000 0 input voltage (px.x - gnd) vref x (1023/1024) vref x (128/1024) vref x (64/1024) ad0wint not affected ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0lth:adc0ltl adc0gth:adc0gtl figure 5.16. adc window compare example: left-justified single-ended data
c8051f320/1 rev. 1.1 53 5.4.2. window detector in differential mode figure 5.17 shows two example window comparisons for right-justified, differential data, with adc0lth:adc0ltl = 0x0040 (+64d) and adc0gth:adc0gth = 0xffff (-1d). in differential mode, the mea - surable voltage between the input pins is between -vref and vref*(511/512). output co des are represented as 10- bit 2?s complement signed integers. in the left example, an ad0wint interrupt will be generated if the adc0 con - version word (adc0h:adc0l) is within the range defined by adc0gth:adc0gtl and adc0lth:adc0ltl (if 0xffff (-1d) < adc0h:adc0l < 0x0040 (64d)). in the right example, an ad0wint interrupt will be generated if the adc0 conversion word is outside of the range defined by the adc0gt and adc0lt registers (if adc0h:adc0l < 0xffff (-1d) or adc0h:adc0l > 0x0040 (+64d)). figure 5.18 shows an example using left-justified data with equivalent adc0gt and adc0lt register settings.. 0x01ff 0x0041 0x0040 0x003f 0x0000 0xffff 0xfffe 0x0200 -vref input voltage (px.x - px.x) vref x (511/512) vref x (64/512) vref x (-1/512) 0x01ff 0x0041 0x0040 0x003f 0x0000 0xffff 0xfffe 0x0200 -vref input voltage (px.x - px.x) vref x (511/512) vref x (64/512) vref x (-1/512) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl ad0wint not affected ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0gth:adc0gtl adc0lth:adc0ltl figure 5.17. adc window compare example: right-justified differential data 0x7fc0 0x1040 0x1000 0x0fc0 0x0000 0xffc0 0xff80 0x8000 -vref input voltage (px.x - px.y) vref x (511/512) vref x (64/512) vref x (-1/512) 0x7fc0 0x1040 0x1000 0x0fc0 0x0000 0xffc0 0xff80 0x8000 -vref input voltage (px.x - px.x) vref x (511/512) vref x (64/512) vref x (-1/512) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl ad0wint not affected adc0gth:adc0gtl ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0lth:adc0ltl figure 5.18. adc window compare exampl e: left-justified differential data
c8051f320/1 54 rev. 1.1 table 5.1. adc0 electrical characteristics vdd = 3.0 v, vref = 2.40 v, -40c to +85c unless otherwise specified parameter conditions min typ max units dc accuracy resolution 10 bits integral nonlinearity 0.5 1 lsb differential nonlinearity guaranteed monotonic 0.5 1 lsb offset error 0 lsb full scale error -1 lsb offset temperature coefficient 10 ppm/c dynamic performance (10 khz sine-wave single-ended input, 1 db below full scale, 200 ksps) signal-to-noise plus distortion 53 55.5 db total harmonic distortion up to the 5 th harmonic -67 db spurious-free dynamic range 78 db conversion rate sar conversion clock 3 mhz conversion time in sar clocks 10 clocks track/hold acquisition time 300 ns throughput rate 200 ksps analog inputs adc input voltage range single ended (ain+ - gnd) differential (ain+ - ain-) 0 -vref vref vref v v absolute pin voltage with respect to gnd single ended or differential 0 vdd v input capacitance 5 pf temperature sensor linearity note 1 0.1 c gain note 2 2.86 mv / c offset notes 1, 2 (temp = 0 c) 0.776 8.5 mv power specifications power supply current (vdd sup - plied to adc0) operating mode, 200 ksps 400 900 a power supply rejection 0.3 mv/v note 1: includes adc offset, gain, and linearity variations. note 2: represents one standard deviation from the mean.
c8051f320/1 rev. 1.1 55 6. voltage reference the voltage reference mux on c8051f320/1 devices is configurable to us e an externally connected voltage refer - ence, the internal reference voltage genera tor, or the power supply voltage vdd (see figure 6.1 ). the refsl bit in the reference control register (ref0cn) selects the reference source. for the internal reference or an external source, refsl should be set to ?0?; for vdd as th e reference source, refsl should be set to ?1?. the biase bit enables the internal adc bias generator, which is used by the adc and internal oscillator. this enable is forced to logic 1 when either of the aforementioned peripherals is enabled. the adc bias generator may be enabled manually by writing a ?1? to the biase bit in register ref0cn; see figure 6.2 for ref0cn register details. the reference bias generator (see figure 6.1 ) is used by the internal voltage reference, temperature sensor, and clock multiplier. the reference bias is automatically enabled when any of the aforementioned peripherals are enabled. the electrical sp ecifications for the voltage referen ce and bias circuits are given in table 6.1 . important note about the vref input: port pin p0.7 is used as the external vref input. when using an external voltage reference, p0.7 should be configured as analog in put and skipped by the digital crossbar. to configure p0.7 as analog input, set to ?0? bit7 in register p0mdin. to configure the crossbar to skip p0.7, set to ?1? bit7 in register p0skip. refer to section ?14. port input/output? on page 127 for complete port i/o configuration details. the temperature sensor connects to the adc0 positive input multiplexer (see section ?5.1. analog multiplexer? on page 40 for details). the tempe bit in register ref0cn enab les/disables the temperatur e sensor. while disabled, the temperature sensor defaults to a high impedance st ate and any adc0 measurements performed on the sensor result in meaningless data. figure 6.1. voltage referenc e functional block diagram vref (to adc) to analog mux vdd vref r1 vdd external voltage reference circuit gnd temp sensor en 0 1 ref0cn refsl tempe biase refbe refbe internal reference en reference bias en clkmul enable tempe to clock multiplier, temp sensor adc bias to adc, internal oscillator en ioscen ad0en
c8051f320/1 56 rev. 1.1 table 6.1. voltage reference electrical characteristics vdd = 3.0 v; -40c to +85c unles s otherwise specified parameter conditions min typ max units internal reference (refbe = 1) output voltage 25c ambient 2.38 2.44 2.50 v vref short-circuit current 10 ma vref temperature coefficient 15 ppm/c load regulation load = 0 to 200 a to gnd 1.5 ppm/a vref turn-on time 1 4.7f tantalum, 0.1f ceramic bypass 2 ms vref turn-on time 2 0.1f ceramic bypass 20 s vref turn-on time 3 no bypass cap 10 s power supply rejection 140 ppm/v external reference (refbe = 0) input voltage range 0 vdd v input current sample rate = 200 ksps; vref = 3.0 v 12 a bias generators adc bias generator biase = ?1? 100 a reference bias generator 40 a figure 6.2. ref0cn: reference control register bits7-3: unused. read = 00000b; write = don?t care. bit3: refsl: voltage reference select. this bit selects the source for the internal voltage reference. 0: vref pin used as voltage reference. 1: vdd used as voltage reference. bit2: tempe: temperature sensor enable bit. 0: internal temperature sensor off. 1: internal temperature sensor on. bit1: biase: internal analog bias generator enable bit. 0: internal bias generator off. 1: internal bias generator on. bit0: refbe: internal reference buffer enable bit. 0: internal reference buffer disabled. 1: internal reference buffer enabled. intern al voltage reference driven on the vref pin. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - refsl tempe biase refbe 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xd1
c8051f320/1 rev. 1.1 57 7. comparators c8051f320/1 devices include two on-chip programmable voltage comparators: comparator0 is shown in figure 7.1 ; comparator1 is shown in figure 7.2 . the two comparators oper ate identically with the following exceptions: (1) their input selections differ as shown in figure 7.1 and figure 7.2 ; (2) comparator0 can be used as a reset source. each comparator offers pr ogrammable response time and hysteresis, an analog input multiplexer, and two outputs that are optionally available at the port pins: a synchron ous ?latched? output (cp0, cp1) , or an asynchronous ?raw? output (cp0a, cp1a). the asynchronous signal is available ev en when the system clock is not active. this allows the comparators to operate and generate an output with the devi ce in stop mode. when assign ed to a port pin, the com - parator outputs may be configured as open drain or push-pull (see section ?14.2. port i/o initialization? on page 131 ). comparator0 may also be used as a reset source (see section ?10.5. comparator0 reset? on page 102 ). the comparator0 inputs are selected in the cpt0mx register ( figure 7.5 ). the cmx0p1-cmx0p0 bits select the comparator0 positive input; the cmx0n1-cmx0n0 bits sel ect the comparator0 negative input. the comparator1 inputs are selected in the cpt1mx register ( figure 7.8 ). the cmx1p1-cmx1p0 bits select the comparator1 posi - tive input; the cmx1n1-cmx1n0 bits select the comparator1 negative input. important note about comparator inputs: the port pins selected as comparator inputs should be configured as analog inputs in their associated port configuration register, and configured to be skipped by the crossbar (for details on port configuration, see section ?14.3. general purpose po rt i/o? on page 134 ). vdd cpt0cn reset decision tree + - crossbar interrupt logic q q set clr d q q set clr d (synchronizer) gnd cp0 + p1.0 p1.4 p2.0 p2.4 cp0 - p1.1 p1.5 p2.1 p2.5 cp0en cp0out cp0rif cp0fif cp0hyp1 cp0hyp0 cp0hyn1 cp0hyn0 cpt0mx cmx0n1 cmx0n0 cmx0p1 cmx0p0 cpt0md cp0rie cp0fie cp0md1 cp0md0 cp0 cp0a cp0 rising-edge cp0 falling-edge cp0 interrupt cp0rie cp0fie note: p2.4 and p2.5 available only on c8051f320 figure 7.1. comparator0 fu nctional block diagram
c8051f320/1 58 rev. 1.1 comparator outputs can be polled in softwa re, used as an interrupt source, and/or routed to a port pin. when routed to a port pin, comparator outputs are available asynchronous or synchronous to the system clock; the asynchronous out - put is available even in stop mode (with no system clock active). when disabled, the comparator output (if assigned to a port i/o pin via the crossbar) defaults to th e logic low state, and supply current falls to less than 100 na. see section ?14.1. priority crossbar decoder? on page 129 for details on configuring comparator outputs via the digital crossbar. comparator inputs can be externally driven from -0.25 v to (vdd) + 0.25 v without damage or upset. the complete comparator electrical speci fications are given in table 7.1 . comparator response time may be configured in software via the cptnmd registers (see figure 7.6 and figure 7.9 ). selecting a longer response time reduces the comparator supply current. see table 7.1 for complete timing and sup - ply current specifications. figure 7.2. comparator1 fu nctional block diagram vdd cpt1cn + - crossbar interrupt logic q q set clr d q q set clr d (synchronizer) gnd cp1 + p1.2 p1.6 p2.2 p2.6 cp1 - p1.3 p1.7 p2.3 p2.7 cp1en cp1out cp1rif cp1fif cp1hyp1 cp1hyp0 cp1hyn1 cp1hyn0 cpt1mx cmx1n1 cmx1n0 cmx1p1 cmx1p0 cpt1md cp1rie cp1fie cp1md1 cp1md0 cp1 cp1a cp1 rising-edge cp1 falling-edge cp1 interrupt cp1rie cp1fie note: p2.6 and p2.7 available only on c8051f320
c8051f320/1 rev. 1.1 59 comparator hysteresis is programmed using bits3-0 in the comparator control register cptncn (shown in figure 7.4 and figure 7.7 ). the amount of negative hysteresis voltage is determined by the settings of the cpnhyn bits. as shown in figure 7.3 , settings of 20, 10 or 5 mv of negative hysteresis can be programmed, or negative hysteresis can be disabled. in a similar way, the amount of positive hysteresis is determined by the setting the cpnhyp bits. comparator interrupts can be generated on both rising-edge and falling-edge out put transitions. (for interrupt enable and priority control, see section ?8.3. interrupt handler? on page 58 .) the cpnfif flag is set to ?1? upon a com - parator falling-edge, and the cpnrif flag is set to ?1? up on the comparator rising-edge. once set, these bits remain set until cleared by software. the output state of the comparator can be obtain ed at any time by reading the cpnout bit. the comparator is enabled by setting the cpnen bit to ?1?, and is disabled by clearing this bit to ?0?. positive hysteresis voltage (programmed with cp0hyp bits) negative hysteresis voltage (programmed by cp0hyn bits) vin- vin+ inputs circuit configuration + _ cp0+ cp0- cp0 vin+ vin- out v oh positive hysteresis disabled maximum positive hysteresis negative hysteresis disabled maximum negative hysteresis output v ol figure 7.3. comparator hysteresis plot
c8051f320/1 60 rev. 1.1 figure 7.4. cpt0cn: compar ator0 control register bit7: cp0en: comparator0 enable bit. 0: comparator0 disabled. 1: comparator0 enabled. bit6: cp0out: comparator 0 output state flag. 0: voltage on cp0+ < cp0-. 1: voltage on cp0+ > cp0-. bit5: cp0rif: comparator0 rising-edge flag. 0: no comparator0 rising edge has occu rred since this flag was last cleared. 1: comparator0 rising edge has occurred. bit4: cp0fif: comparator0 falling-edge flag. 0: no comparator0 falling-edge has occurred since this flag was last cleared. 1: comparator0 falling-edge interrupt has occurred. bits3-2: cp0hyp1-0: comparator0 po sitive hysteresis control bits. 00: positive hysteresis disabled. 01: positive hysteresis = 5 mv. 10: positive hysteresis = 10 mv. 11: positive hysteresis = 20 mv. bits1-0: cp0hyn1-0: comparator0 negative hysteresis control bits. 00: negative hysteresis disabled. 01: negative hysteresis = 5 mv. 10: negative hysteresis = 10 mv. 11: negative hysteresis = 20 mv. r/w r r/w r/w r/w r/w r/w r/w reset value cp0en cp0out cp0rif cp0fif cp0hyp1 cp0hyp0 cp0hyn1 cp0hyn0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x9b
c8051f320/1 rev. 1.1 61 figure 7.5. cpt0mx: comparator0 mux selection register bits7-6: unused. read = 00b, write = don?t care. bits5-4: cmx0n1-cmx0n0: comparator0 negative input mux select. these bits select which port pin is used as the comparator0 negative input. bits3-2: unused. read = 00b, write = don?t care. bits1-0: cmx0p1-cmx0p0: comparator0 positive input mux select. these bits select which port pin is us ed as the comparator0 positive input. ? note: p2.4 and p2.5 available only on c8051f320 devices; selection reserved on C8051F321 devices. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - cmx0n1 cmx0n0 - - cmx0p1 cmx0p0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x9f cmx0n1 cmx0n0 negative input 00 p1.1 01 p1.5 10 p2.1 11 p2.5 ? cmx0p1 cmx0p0 positive input 00 p1.0 01 p1.4 10 p2.0 11 p2.4 ?
c8051f320/1 62 rev. 1.1 figure 7.6. cpt0md: comparator 0 mode selection register bits7-6: unused. read = 00b. write = don?t care. bit5: cp0rie: comparator0 rising-edge interrupt enable. 0: comparator0 rising-edge interrupt disabled. 1: comparator0 rising-edge interrupt enabled. bit4: cp0fie: comparator0 falling-edge interrupt enable. 0: comparator0 falling-edge interrupt disabled. 1: comparator0 falling- edge interrupt enabled. bits3-2: unused. read = 00b. write = don?t care. bits1-0: cp0md1-cp0md0: comparator0 mode select these bits select the respon se time for comparator0. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - cp0rie cp0fie - - cp0md1 cp0md0 00000010 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x9d mode cp0md1 cp0md0 cp0 response time (typ) 0 0 0 100 ns 1 0 1 175 ns 2 1 0 320 ns 3 1 1 1050 ns
c8051f320/1 rev. 1.1 63 figure 7.7. cpt1cn: compar ator1 control register bit7: cp1en: comparator1 enable bit. 0: comparator1 disabled. 1: comparator1 enabled. bit6: cp1out: comparator 1 output state flag. 0: voltage on cp1+ < cp1-. 1: voltage on cp1+ > cp1-. bit5: cp1rif: comparator1 rising-edge flag. 0: no comparator1 rising edge has occu rred since this flag was last cleared. 1: comparator1 rising edge has occurred. bit4: cp1fif: comparator1 falling-edge flag. 0: no comparator1 falling-edge has occurred since this flag was last cleared. 1: comparator1 falling-edge has occurred. bits3-2: cp1hyp1-0: comparator1 po sitive hysteresis control bits. 00: positive hysteresis disabled. 01: positive hysteresis = 5 mv. 10: positive hysteresis = 10 mv. 11: positive hysteresis = 20 mv. bits1-0: cp1hyn1-0: comparator1 negative hysteresis control bits. 00: negative hysteresis disabled. 01: negative hysteresis = 5 mv. 10: negative hysteresis = 10 mv. 11: negative hysteresis = 20 mv. r/w r r/w r/w r/w r/w r/w r/w reset value cp1en cp1out cp1rif cp1fif cp1hyp1 cp1hyp0 cp1hyn1 cp1hyn0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x9a
c8051f320/1 64 rev. 1.1 figure 7.8. cpt1mx: comparator1 mux selection register bits7-6: unused. read = 00b, write = don?t care. bits5-4: cmx1n1-cmx1n0: comparator1 negative input mux select. these bits select which port pin is used as the comparator1 negative input. bits3-2: unused. read = 00b, write = don?t care. bits1-0: cmx1p1-cmx1p0: comparator1 positive input mux select. these bits select which port pin is us ed as the comparator1 positive input. ? note: p2.6 and p2.7 available only on c8051f320 devices; selection reserved on C8051F321 devices. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - cmx1n1 cmx1n0 - - cmx1p1 cmx1p0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x9e cmx1n1 cmx1n0 negative input 00 p1.3 01 p1.7 10 p2.3 11 p2.7 ? cmx1p1 cmx1p0 positive input 00 p1.2 01 p1.6 10 p2.2 11 p2.6 ?
c8051f320/1 rev. 1.1 65 figure 7.9. cpt1md: comparator 1 mode selection register bits7-6: unused. read = 00b, write = don?t care. bit5: cp1rie: comparator1 rising-edge interrupt enable. 0: comparator1 rising-edge interrupt disabled. 1: comparator1 rising-edge interrupt enabled. bit4: cp1fie: comparator1 falling-edge interrupt enable. 0: comparator1 falling-edge interrupt disabled. 1: comparator1 falling- edge interrupt enabled. bits1-0: cp1md1-cp1md0: comparator1 mode select. these bits select the respon se time for comparator1. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - cp1rie cp1fie - - cp1md1 cp1md0 00000010 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x9c mode cp1md1 cp1md0 cp1 response time (typ) 0 0 0 100 ns 1 0 1 175 ns 2 1 0 320 ns 3 1 1 1050 ns
c8051f320/1 66 rev. 1.1 table 7.1. comparator electric al characteristics vdd = 3.0 v, -40c to +85c unless otherwise noted. all specifications apply to both comparat or0 and comparator1 unless otherwise noted. parameter conditions min typ max units response time: mode 0, vcm ? = 1.5 v cp0+ - cp0- = 100 mv 100 ns cp0+ - cp0- = -100 mv 250 ns response time: mode 1, vcm ? = 1.5 v cp0+ - cp0- = 100 mv 175 ns cp0+ - cp0- = -100 mv 500 ns response time: mode 2, vcm ? = 1.5 v cp0+ - cp0- = 100 mv 320 ns cp0+ - cp0- = -100 mv 1100 ns response time: mode 3, vcm ? = 1.5 v cp0+ - cp0- = 100 mv 1050 ns cp0+ - cp0- = -100 mv 5200 ns common-mode rejection ratio 1.5 4 mv/v positive hysteresis 1 cp0hyp1-0 = 00 0 1 mv positive hysteresis 2 cp0hyp1-0 = 01 2 5 10 mv positive hysteresis 3 cp0hyp1-0 = 10 7 10 20 mv positive hysteresis 4 cp0hyp1-0 = 11 15 20 30 mv negative hysteresis 1 cp0hyn1-0 = 00 0 1 mv negative hysteresis 2 cp0hyn1-0 = 01 2 5 10 mv negative hysteresis 3 cp0hyn1-0 = 10 7 10 20 mv negative hysteresis 4 cp0hyn1-0 = 11 15 20 30 mv inverting or non-inverting input voltage range -0.25 vdd + 0.25 v input capacitance 3 pf input bias current 0.001 na input offset voltage -5 +5 mv power supply power supply rejection 0.1 mv/v power-up time 10 s supply current at dc mode 0 7.6 a mode 1 3.2 a mode 2 1.3 a mode 3 0.4 a ? vcm is the common-mode voltage on cp0+ and cp0-.
c8051f320/1 rev. 1.1 67 8. voltage regulator (reg0) c8051f320/1 devices include a 5 v-to-3 v voltage regulator (reg0). when enabled, the reg0 output appears on the vdd pin and can be used to power external devices. reg0 can be enabled/disabled by software using bit regen in register reg0cn. see table 8.1 for reg0 electrical characteristics. note that the vbus signal must be connected to the vb us pin when using the device in a usb network. the vbus signal should only be connected to the regin pin when operating the device as a bus-powered function. reg0 con - figuration options are shown in figure 8.1 - figure 8.4 .
c8051f320/1 68 rev. 1.1 8.1. regulator mode selection reg0 offers a low power mode intended for use when the device is in suspend mode. in this low power mode, the reg0 output remains as specified; however the reg0 dynamic performance (response time) is degraded. see table 8.1 for normal and low power mode supply current specifi cations. the reg0 mode selection is controlled via the regmod bit in register reg0cn.
c8051f320/1 rev. 1.1 69 8.2. vbus detection when the usb function contro ller is used (see section section ?15. universal serial bus controller (usb0)? on page 143 ), the vbus signal should be conn ected to the vbus pin. the vbstat bit (register reg0cn) indicates the current logic level of the vbus si gnal. if enabled, a vbus interrupt wi ll be generated when the vbus signal matches the polarity selected by the vbpol bit in regist er reg0cn. the vbus interrupt is level-sensitive, and has no associated interrupt pending flag. the vbus interrupt wi ll be active as long as the vbus signal matches the polarity selected by vbpol. see table 8.1 for vbus input parameters. important note: when usb is selected as a reset source, a system reset will be generated when the vbus signal matches the polarity select ed by the vbpol bit. see section ?10. reset sources? on page 99 for details on selecting usb as a reset source. table 8.1. voltage regulator elec trical specifications vdd = 3.0 v; -40c to +85c unless otherwise specified parameter conditions min typ max units input voltage range 4.0 5.25 v output voltage output current = 1 to 100 ma 3.0 3.3 3.6 v vbus detection input threshold 1.0 1.8 4.0 v bias current normal mode (regmod = ?0?) low power mode (regmod = ?1?) 90 60 tbd tbd a
c8051f320/1 70 rev. 1.1 voltage regulator (reg0) 5v in 3v out vbus sense regin vbus from vbus to 3v power net device power net vdd c8051f320/1 figure 8.1. reg0 configuration: usb bus-powered voltage regulator (reg0) 5v in 3v out vbus sense regin vbus to 3v power net device power net vdd c8051f320/1 from 5v power net from vbus figure 8.2. reg0 configur ation: usb self-powered
c8051f320/1 rev. 1.1 71 voltage regulator (reg0) 5v in 3v out vbus sense regin vbus from 3v power net device power net vdd c8051f320/1 from vbus figure 8.3. reg0 configuration: us b self-powered, regulator disabled voltage regulator (reg0) 5v in 3v out vbus sense regin vbus to 3v power net device power net vdd c8051f320/1 from 5v power net figure 8.4. reg0 configuration: no usb connection
c8051f320/1 72 rev. 1.1 figure 8.5. reg0cn: voltage regulator control bit7: regdis: voltag e regulator disable. 0: voltage regulator enabled. 1: voltage regulator disabled. bit6: vbstat: vbus signal status. 0: vbus signal currently absent (d evice not attached to usb network). 1: vbus signal currently preset (device attached to usb network). bit5: vbpol: vbus interrupt polarity select. this bit selects the vbus interrupt polarity. 0: vbus interrupt active when vbus is low. 1: vbus interrupt active when vbus is high. bit4: regmod: voltage regulator mode select. this bit selects the voltage regulator mode. when regmod is set to ?1?, the voltage regulator oper- ates in low power (suspend) mode. 0: usb0 voltage regulator in normal mode. 1: usb0 voltage regulator in low power mode. bits3-0: reserved. read = 0000b. must write = 0000b. r/w r r/w r/w r/w r/w r/w r/w reset value regdis vbstat vbpol regmod reserved reserved reserved reserved 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc9
c8051f320/1 rev. 1.1 73 9. cip-51 microcontroller the mcu system controller core is th e cip-51 microcontroller. the cip-51 is fully compatible with the mcs-51? instruction set; standard 803x/805x assemblers and compilers can be used to develop software. the mcu family has a superset of all the peripherals included with a standard 8051. included are four 16-bit counter/timers (see descrip - tion in section 19 ), an enhanced full-duplex uart (see description in section 17 ), an enhanced spi (see description in section 18 ), 256 bytes of internal ram, 128 byte special function regi ster (sfr) address space ( section 9.2.6 ), and 25 port i/o (see description in section 14 ). the cip-51 also includes on-chip debug hardware (see description in section 21 ), and interfaces directly with the analog and digital subsystems providi ng a complete data acquisition or control-system solution in a single integrated circuit. the cip-51 microcontroller core implemen ts the standard 8051 organization and peripherals as well as additional custom peripherals and functions to extend its capability (see figure 9.1 for a block diagram). the cip-51 includes the following features: data bus tmp1 tmp2 prgm. address reg. pc incrementer alu psw data bus data bus memory interface mem_address d8 pipeline buffer data pointer interrupt interface system_irqs emulation_irq mem_control control logic a16 program counter (pc) stop clock reset idle power control register data bus sfr bus interface sfr_address sfr_control sfr_write_data sfr_read_data d8 d8 b register d8 d8 accumulator d8 d8 d8 d8 d8 d8 d8 d8 mem_write_data mem_read_data d8 sram address register sram (256 x 8) d8 stack pointer d8 figure 9.1. cip-51 block diagram - fully compatible with mcs-51 instruction set - 25 mips peak throughput with 25 mhz clock - 0 to 25 mhz clock frequency - 256 bytes of internal ram - 25 port i/o - extended interrupt handler - reset input - power management modes - on-chip debug logic - program and data memory security
c8051f320/1 74 rev. 1.1 performance the cip-51 employs a pipelined architectur e that greatly increases its instruct ion throughput over the standard 8051 architecture. in a standard 8051, all instructions except for mul and div take 12 or 24 system clock cycles to exe - cute, and usually have a maximum system clock of 12 mhz. by contrast, the cip-51 core executes 70% of its instruc - tions in one or two system clock cycles, with no inst ructions taking more than eight system clock cycles. with the cip-51's maxi mum system clock at 25 mhz, it has a peak throughput of 25 mips. the cip-51 has a total of 109 instructions. the table below shows the total number of instructions that for execution time. programming and debugging support in-system programming of the flash program memory and communication with on-chip debug support logic is accomplished via the silicon labs 2-wi re development interface (c2). note that the re-programmable flash can also be read and changed a single byte at a time by the application software using the movc and movx instruc - tions. this feature allows program memory to be used for no n-volatile data storage as we ll as updating program code under software control. the on-chip debug support logic facilitates full speed in-c ircuit debugging, allowing the setting of hardware break - points, starting, stopping and single stepping through progra m execution (including interrupt service routines), exam - ination of the program's call stack, and reading/writing the contents of registers and memory. this method of on-chip debugging is completely non-intrusive, requiring no ram, stack, timers, or other on-chip resources. c2 details can be found in section ?21. c2 interface? on page 253 . the cip-51 is supported by development tools from silicon labs and third party vendors. silicon labs provides an integrated development environment (ide) including edit or, macro assembler, debugger and programmer. the ide's debugger and programmer interface to the cip-51 via the c2 interface to provide fast and efficient in-system device programming and debugging. third party macro as semblers and c compilers are also available. clocks to execute 1 2 2/3 3 3/4 4 4/5 5 8 number of instructions 26 50 5 14 7 3 1 2 1
c8051f320/1 rev. 1.1 75 9.1. instruction set the instruction set of the cip-51 system controller is fully compatible with the standard mcs-51? instruction set. standard 8051 development tools can be used to develop so ftware for the cip-51. all ci p-51 instructions are the binary and functional equivalent of their mcs-51? counterparts, including opcodes, addressing modes and effect on psw flags. however, instruction timing is different than that of the standard 8051. 9.1.1. instruction and cpu timing in many 8051 implementations, a distinction is made between machine cycles and clock cycles, with machine cycles varying from 2 to 12 clock cycles in length. however, the cip-51 implementation is based solely on clock cycle tim - ing. all instruction timings are specified in terms of clock cycles. due to the pipelined architectur e of the cip-51, most instructions execute in the same number of clock cycles as there are program bytes in the instruction. conditional branch inst ructions take one less clock cycle to complete when the branch is not taken as opposed to when the branch is taken. table 9.1 is the cip-51 instruction set summary, which includes the mnemonic, number of bytes, and number of clock cycles for each instruction. 9.1.2. movx instruction and program memory the movx instruction is typically used to access external data memory (note: the c8051f320/1 does not support off-chip data or program memory). in the cip-51, the movx wr ite instruction is used to accesses external ram (xram) and the on-chip program me mory space implemented as re-programmable flash memory. the flash access feature provides a mechanism for the cip-51 to update program code and use the program memory space for non-volatile data storage. refer to section ?11. flash memory? on page 107 for further details. table 9.1. cip-51 instruction set summary mnemonic description bytes clock cycles arithmetic operations add a, rn add register to a 1 1 add a, direct add direct byte to a 2 2 add a, @ri add indirect ram to a 1 2 add a, #data add immediate to a 2 2 addc a, rn add register to a with carry 1 1 addc a, direct add direct byte to a with carry 2 2 addc a, @ri add indirect ram to a with carry 1 2 addc a, #data add immediate to a with carry 2 2 subb a, rn subtract register from a with borrow 1 1 subb a, direct subtract direct byte from a with borrow 2 2 subb a, @ri subtract indirect ram from a with borrow 1 2 subb a, #data subtract immediate from a with borrow 2 2 inc a increment a 1 1 inc rn increment register 1 1 inc direct increment direct byte 2 2 inc @ri increment indirect ram 1 2 dec a decrement a 1 1 dec rn decrement register 1 1 dec direct decrement direct byte 2 2 dec @ri decrement indirect ram 1 2 inc dptr increment data pointer 1 1
c8051f320/1 76 rev. 1.1 mul ab multiply a and b 1 4 div ab divide a by b 1 8 da a decimal adjust a 1 1 logical operations anl a, rn and register to a 1 1 anl a, direct and direct byte to a 2 2 anl a, @ri and indirect ram to a 1 2 anl a, #data and immediate to a 2 2 anl direct, a and a to direct byte 2 2 anl direct, #data and immediate to direct byte 3 3 orl a, rn or register to a 1 1 orl a, direct or direct byte to a 2 2 orl a, @ri or indirect ram to a 1 2 orl a, #data or immediate to a 2 2 orl direct, a or a to direct byte 2 2 orl direct, #data or immediate to direct byte 3 3 xrl a, rn exclusive-or register to a 1 1 xrl a, direct exclusive-or direct byte to a 2 2 xrl a, @ri exclusive-or indirect ram to a 1 2 xrl a, #data exclusive-or immediate to a 2 2 xrl direct, a exclusive-or a to direct byte 2 2 xrl direct, #data exclusive-or immedi ate to direct byte 3 3 clr a clear a 1 1 cpl a complement a 1 1 rl a rotate a left 1 1 rlc a rotate a left through carry 1 1 rr a rotate a right 1 1 rrc a rotate a right through carry 1 1 swap a swap nibbles of a 1 1 data transfer mov a, rn move register to a 1 1 mov a, direct move direct byte to a 2 2 mov a, @ri move indirect ram to a 1 2 mov a, #data move immediate to a 2 2 mov rn, a move a to register 1 1 mov rn, direct move direct byte to register 2 2 mov rn, #data move immediate to register 2 2 mov direct, a move a to direct byte 2 2 mov direct, rn move register to direct byte 2 2 mov direct, direct move direct byte to direct byte 3 3 mov direct, @ri move indirect ram to direct byte 2 2 mov direct, #data move immediate to direct byte 3 3 mov @ri, a move a to indirect ram 1 2 mov @ri, direct move direct byte to indirect ram 2 2 mov @ri, #data move immediate to indirect ram 2 2 table 9.1. cip-51 instruction set summary mnemonic description bytes clock cycles
c8051f320/1 rev. 1.1 77 mov dptr, #data16 load dptr with 16-bit constant 3 3 movc a, @a+dptr move code byte relative dptr to a 1 3 movc a, @a+pc move code byte relative pc to a 1 3 movx a, @ri move external data (8-bit address) to a 1 3 movx @ri, a move a to external data (8-bit address) 1 3 movx a, @dptr move external data (16-bit address) to a 1 3 movx @dptr, a move a to external data (16-bit address) 1 3 push direct push direct byte onto stack 2 2 pop direct pop direct byte from stack 2 2 xch a, rn exchange register with a 1 1 xch a, direct exchange direct byte with a 2 2 xch a, @ri exchange indirect ram with a 1 2 xchd a, @ri exchange low nibble of indirect ram with a 1 2 boolean manipulation clr c clear carry 1 1 clr bit clear direct bit 2 2 setb c set carry 1 1 setb bit set direct bit 2 2 cpl c complement carry 1 1 cpl bit complement direct bit 2 2 anl c, bit and direct bit to carry 2 2 anl c, /bit and complement of direct bit to carry 2 2 orl c, bit or direct bit to carry 2 2 orl c, /bit or complement of direct bit to carry 2 2 mov c, bit move direct bit to carry 2 2 mov bit, c move carry to direct bit 2 2 jc rel jump if carry is set 2 2/3 jnc rel jump if carry is not set 2 2/3 jb bit, rel jump if direct bit is set 3 3/4 jnb bit, rel jump if direct bit is not set 3 3/4 jbc bit, rel jump if direct bit is set and clear bit 3 3/4 program branching acall addr11 absolute subroutine call 2 3 lcall addr16 long subroutine call 3 4 ret return from subroutine 1 5 reti return from interrupt 1 5 ajmp addr11 absolute jump 2 3 ljmp addr16 long jump 3 4 sjmp rel short jump (relative address) 2 3 jmp @a+dptr jump indirect relative to dptr 1 3 jz rel jump if a equals zero 2 2/3 jnz rel jump if a does not equal zero 2 2/3 cjne a, direct, rel compare direct byte to a and jump if not equal 3 3/4 cjne a, #data, rel compare immediate to a and jump if not equal 3 3/4 cjne rn, #data, rel compare immediate to regist er and jump if not equal 3 3/4 table 9.1. cip-51 instruction set summary mnemonic description bytes clock cycles
c8051f320/1 78 rev. 1.1 cjne @ri, #data, rel compare immediate to indir ect and jump if not equal 3 4/5 djnz rn, rel decrement register an d jump if not zero 2 2/3 djnz direct, rel decrement direct byte and jump if not zero 3 3/4 nop no operation 1 1 table 9.1. cip-51 instruction set summary mnemonic description bytes clock cycles notes on registers, operands and addressing modes: rn - register r0-r7 of the curr ently selected register bank. @ri - data ram location addressed indirectly through r0 or r1. rel - 8-bit, signed (two?s complement) offset relative to th e first byte of the following instruction. used by sjmp and all conditional jumps. direct - 8-bit internal data location?s address. this coul d be a direct-access data ra m location (0x00-0x7f) or an sfr (0x80-0xff). #data - 8-bit constant #data16 - 16-bit constant bit - direct-accessed bit in data ram or sfr addr11 - 11-bit destination address used by acall and ajmp . the destination must be within the same 2k-byte page of program memory as the first byte of the following instruction. addr16 - 16-bit destination address used by lcall and ljmp. the destination may be anywhere within the 8k- byte program memory space. there is one unused opcode (0xa5) that performs the same function as nop. all mnemonics copyrighted ? intel corporation 1980.
c8051f320/1 rev. 1.1 79 9.2. memory organization the memory organization of the cip-51 system controller is similar to that of a standard 8051. there are two sepa - rate memory spaces: program memory and data memory. pr ogram and data memory share the same address space but are accessed via different instru ction types. the cip-51 memo ry organization is shown in figure 9.2 . 9.2.1. program memory the cip-51 core has a 64k-byte program memory space. the c8051f320/1 implements 16k bytes of this program memory space as in-system, re-programmable flash memo ry, organized in a contig uous block from addresses 0x0000 to 0x3fff. addresses above 0x3dff are reserved. program memory is normally assumed to be read-only. ho wever, the cip-51 can write to program memory by setting the program store write enable bit (p sctl.0) and using the movx instruction. this feature provides a mechanism for the cip-51 to update program code and use the program memory space for non-volatile data storage. refer to sec - tion ?11. flash memory? on page 107 for further details. figure 9.2. memory map program/data memory (flash) (direct and indirect addressing) 0x00 0x7f upper 128 ram (indirect addressing only) 0x80 0xff special function register's (direct addressing only) data memory (ram) general purpose registers 0x1f 0x20 0x2f bit addressable lower 128 ram (direct and indirect addressing) 0x30 internal data address space external data address space xram - 1024 bytes (accessable using movx instruction) 0x0000 0x03ff same 2048 bytes as from 0x0000 to 0x07ff, wrapped on 2k-byte boundaries 0x0400 0xffff 16k flash (in-system programmable in 512 byte sectors) 0x0000 reserved 0x3e00 0x3dff usb fifos 1024 bytes 0x07ff 0x0800
c8051f320/1 80 rev. 1.1 9.2.2. data memory the cip-51 includes 256 of internal ram mapped into the data memory space from 0x00 through 0xff. the lower 128 bytes of data memory are used for general purpose regist ers and scratch pad memory. either direct or indirect addressing may be used to access the lower 128 bytes of data memory. locations 0x00 through 0x1f are addressable as four banks of general purpose registers, each bank consisting of eight byte-wide registers. the next 16 bytes, loca - tions 0x20 through 0x2f, may either be addressed as bytes or as 128 bit locations accessible wi th the direct address - ing mode. the upper 128 bytes of data memory are accessible only by indir ect addressing. this regi on occupies the same address space as the special function regi sters (sfr) but is physically separa te from the sfr space. the addressing mode used by an instruction when accessing locations above 0x7f determ ines whether the cpu accesses the upper 128 bytes of data memory space or the sfrs. instructions that use direct addressing will access the sfr space. instructions using indirect addre ssing above 0x7f access the upper 128 bytes of data memory. figure 9.2 illustrates the data memory organization of the cip-51. 9.2.3. general purpose registers the lower 32 bytes of data memory, locations 0x00 through 0x1f, may be addressed as f our banks of general-purpose registers. each bank consists of eigh t byte-wide registers designated r0 through r7. only one of these banks may be enabled at a time. two bits in the program status word, rs 0 (psw.3) and rs1 (psw.4), se lect the active register bank (see description of the psw in figure 9.6 ). this allows fast cont ext switching when enteri ng subroutines and inter - rupt service routines. indirect addressing mode s use registers r0 and r1 as index registers. 9.2.4. bit addressable locations in addition to direct access to data me mory organized as bytes, the sixteen da ta memory locations at 0x20 through 0x2f are also accessible as 128 individually addressable bits. each bit has a bit address from 0x00 to 0x7f. bit 0 of the byte at 0x20 has bit address 0x00 while bit7 of the byte at 0x20 has bit address 0x07. bit 7 of the byte at 0x2f has bit address 0x7f. a bit access is distingui shed from a full byte access by the type of instruction used (bit source or destination operands as opposed to a byte source or destination). the mcs-51? assembly language allows an alternate notati on for bit addressing of the form xx.b where xx is the byte address and b is the bit position within the byte. for example, the instruction: mov c, 22h.3 moves the boolean value at 0x13 (bit 3 of the byte at location 0x22) into the carry flag. 9.2.5. stack a programmer's stack can be located anyw here in the 256-byte data memory. th e stack area is designated using the stack pointer (sp, 0x81) sfr. the sp will point to the last location used. the next value pushed on the stack is placed at sp+1 and then sp is increm ented. a reset initializes the stack pointer to location 0x07. theref ore, the first value pushed on the stack is placed at location 0x0 8, which is also the first register (r0) of register bank 1. thus, if more than one register bank is to be used, the sp should be in itialized to a location in the data memory not being used for data storage. the stack depth can extend up to 256 bytes.
c8051f320/1 rev. 1.1 81 9.2.6. special function registers the direct-access data memory locations from 0x80 to 0xff const itute the special function registers (sfrs). the sfrs provide control and data exchange with the cip-51's resources and peripher als. the cip-51 d uplicates the sfrs found in a typical 8051 implementation as well as impl ementing additional sfrs used to configure and access the sub-systems unique to the mcu. this allows the addition of new functionality while retaining compatibility with the mcs-51? instruction set. table 9.2 lists the sfrs implemented in the cip-51 system controller. the sfr registers are accessed anytime the direct addressing mode is used to access memory locations from 0x80 to 0xff. sfrs with addresses ending in 0x0 or 0x8 (e.g. p0 , tcon, scon0, ie, etc.) are bit-addressable as well as byte-addressable. all other sfrs are by te-addressable only. unoccupied addre sses in the sfr space are reserved for future use. accessing these areas will have an indeterminat e effect and should be avoided. refer to the corresponding pages of the datasheet, as indicated in table 9.3 , for a detailed description of each register. table 9.3. special function registers sfrs are listed in alphabetical order. all undefined sfr locations are reserved register address description page acc 0xe0 accumulator 86 adc0cf 0xbc adc0 configuration 47 adc0cn 0xe8 adc0 control 49 adc0gth 0xc4 adc0 greater-than compare high 50 adc0gtl 0xc3 adc0 greater-than compare low 50 adc0h 0xbe adc0 high 47 adc0l 0xbd adc0 low 48 adc0lth 0xc6 adc0 less-than compare word high 51 table 9.2. special function register (sfr) memory map f8 spi0cn pca0l pca0h pca0cpl0 pca0cph0 pca0cpl4 pca0cph4 vdm0cn f0 b p0mdin p1mdin p2mdin p3mdin eip1 eip2 e8 adc0cn pca0cpl1 pca0cph1 pca0cpl2 pca0cph2 pca0cpl3 pca0cph3 rstsrc e0 acc xbr0 xbr1 it01cf eie1 eie2 d8 pca0cn pca0md pca0cpm0 pca0cpm1 pca0cpm2 pca0cpm3 pca0cpm4 d0 psw ref0cn p0skip p1skip p2skip usb0xcn c8 tmr2cn reg0cn tmr2rll tmr2rlh tmr2l tmr2h c0 smb0cn smb0cf smb0dat adc0gtl adc0gth adc0ltl adc0lth b8 ip clkmul amx0n amx0p adc0cf adc0l adc0h b0 p3 oscxcn oscicn oscicl flscl flkey a8 ie clksel emi0cn a0 p2 spi0cfg spi0ckr spi0dat p0mdout p1mdout p2mdout p3mdout 98 scon0 sbuf0 cpt1cn cpt0cn cpt1md cpt0md cpt1mx cpt0mx 90 p1 tmr3cn tmr3rll tmr3rlh tmr3l tmr3h usb0adr usb0dat 88 tcon tmod tl0 tl1 th0 th1 ckcon psctl 80 p0 sp dpl dph pcon 0(8) 1(9) 2(a) 3(b) 4(c) 5(d) 6(e) 7(f) (bit addressable)
c8051f320/1 82 rev. 1.1 register address description page no. adc0ltl 0xc5 adc0 less-than compare word low 51 amx0n 0xba amux0 negative channel select 46 amx0p 0xbb amux0 positive channel select 45 b 0xf0 b register 86 ckcon 0x8e clock control 223 clksel 0xa9 clock select 125 cpt0cn 0x9b comparator0 control 60 cpt0md 0x9d comparator0 mode selection 62 cpt0mx 0x9f comparator0 mux selection 61 cpt1cn 0x9a comparator1 control 63 cpt1md 0x9c comparator1 mode selection 65 cpt1mx 0x9e comparator1 mux selection 64 dph 0x83 data pointer high 84 dpl 0x82 data pointer low 84 eie1 0xe6 extended interrupt enable 1 92 eie2 0xe7 extended interrupt enable 2 94 eip1 0xf6 extended interrupt priority 1 93 eip2 0xf7 extended interrupt priority 2 94 emi0cn 0xaa external memory interface control 115 flkey 0xb7 flash lock and key 111 flscl 0xb6 flash scale 111 ie 0xa8 interrupt enable 90 ip 0xb8 interrupt priority 91 it01cf 0xe4 int0/int1 configuration 95 oscicl 0xb3 internal oscillator calibration 119 oscicn 0xb2 internal oscillator control 119 oscxcn 0xb1 external oscillator control 122 p0 0x80 port 0 latch 135 p0mdin 0xf1 port 0 input mode configuration 135 p0mdout 0xa4 port 0 output mode configuration 136 p0skip 0xd4 port 0 skip 136 p1 0x90 port 1 latch 137 p1mdin 0xf2 port 1 input mode configuration 137 p1mdout 0xa5 port 1 output mode configuration 138 p1skip 0xd5 port 1 skip 138 p2 0xa0 port 2 latch 139 p2mdin 0xf3 port 2 input mode configuration 139 p2mdout 0xa6 port 2 output mode configuration 140 p2skip 0xd6 port 2 skip 140 p3 0xb0 port 3 latch 141 p3mdin 0xf4 port 3 input mode configuration 141 p3mdout 0xa7 port 3 output mode configuration 142 pca0cn 0xd8 pca control 248 pca0cph0 0xfc pca capture 0 high 252 pca0cph1 0xea pca capture 1 high 252 pca0cph2 0xec pca capture 2 high 252 table 9.3. special function registers
c8051f320/1 rev. 1.1 83 register address description page no. pca0cph3 0xee pca capture 3high 252 pca0cph4 0xfe pca capture 4 high 252 pca0cpl0 0xfb pca capture 0 low 252 pca0cpl1 0xe9 pca capture 1 low 252 pca0cpl2 0xeb pca capture 2 low 252 pca0cpl3 0xed pca capture 3low 252 pca0cpl4 0xfd pca capture 4 low 252 pca0cpm0 0xda pca module 0 mode register 250 pca0cpm1 0xdb pca module 1 mode register 250 pca0cpm2 0xdc pca module 2 mode register 250 pca0cpm3 0xdd pca module 3 mode register 250 pca0cpm4 0xde pca module 4 mode register 250 pca0h 0xfa pca counter high 251 pca0l 0xf9 pca counter low 251 pca0md 0xd9 pca mode 249 pcon 0x87 power control 97 psctl 0x8f program store r/w control 110 psw 0xd0 program status word 85 ref0cn 0xd1 voltage reference control 56 rstsrc 0xef reset source configuration/status 104 sbuf0 0x99 uart0 data buffer 199 scon0 0x98 uart0 control 198 smb0cf 0xc1 smbus configuration 182 smb0cn 0xc0 smbus control 184 smb0dat 0xc2 smbus data 186 sp 0x81 stack pointer 85 spi0cfg 0xa1 spi configuration 210 spi0ckr 0xa2 spi clock rate control 212 spi0cn 0xf8 spi control 211 spi0dat 0xa3 spi data 213 tcon 0x88 timer/counter control 221 th0 0x8c timer/counter 0 high 224 th1 0x8d timer/counter 1 high 224 tl0 0x8a timer/counter 0 low 224 tl1 0x8b timer/counter 1 low 224 tmod 0x89 timer/counter mode 222 tmr2cn 0xc8 timer/counter 2 control 228 tmr2h 0xcd timer/counter 2 high 229 tmr2l 0xcc timer/counter 2 low 229 tmr2rlh 0xcb timer/counter 2 reload high 229 tmr2rll 0xca timer/counter 2 reload low 229 tmr3cn 0x91 timer/counter 3control 233 tmr3h 0x95 timer/counter 3 high 234 tmr3l 0x94 timer/counter 3low 234 tmr3rlh 0x93 timer/counter 3 reload high 234 tmr3rll 0x92 timer/counter 3 reload low 234 table 9.3. special function registers
c8051f320/1 84 rev. 1.1 9.2.7. register descriptions following are descriptions of sfrs related to the operation of the cip-51 system controller. reserved bits should not be set to logic l. future product versions may use these bits to im plement new features in which case the reset value of the bit will be logic 0, selecting the feature's default state. detailed descriptions of the remaining sfrs are included in the sections of the datasheet associated with their corresponding system function. register address description page no. vdm0cn 0xff vdd monitor control 101 xbr0 0xe1 port i/o crossbar control 0 132 xbr1 0xe2 port i/o crossbar control 1 133 0x84-0x86, 0xab-0xaf, 0xb4, 0xb5, 0xbf, 0xc7, 0xce, 0xcf, 0xd2, 0xd3, 0xdf, 0xe3, 0xe5, 0xf5 reserved table 9.3. special function registers figure 9.3. dpl: data pointer low byte bits7-0: dpl: data pointer low. the dpl register is the low byte of the 16-bit dptr. dptr is us ed to access indirectly addressed memory. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x82 figure 9.4. dph: data pointer high byte bits7-0: dph: data pointer high. the dph register is the high byte of the 16-bit dptr. dptr is used to access indirectly addressed memory. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x83
c8051f320/1 rev. 1.1 85 figure 9.5. sp: stack pointer bits7-0: sp: stack pointer. the stack pointer holds the location of the top of the stack. the stack pointer is incremented before every push operation. the sp register defaults to 0x07 after reset. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x81 figure 9.6. psw: program status word bit7: cy: carry flag. this bit is set when the last arithmetic operation resulted in a carry (addit ion) or a borrow (subtrac- tion). it is cleared to logic 0 by all other arithmetic operations. bit6: ac: auxili ary carry flag this bit is set when the last arithmetic operation resulted in a carry into (addition) or a borrow from (subtraction) the high order nibble. it is cleared to logic 0 by all other arithmetic operations. bit5: f0: user flag 0. this is a bit-addressable, general purpos e flag for use under software control. bits4-3: rs1-rs0: register bank select. these bits select which register ba nk is used during register accesses. bit2: ov: overflow flag. this bit is set to 1 under the following circumstances: ? an add, addc, or subb instructio n causes a sign-change overflow. ? a mul instruction results in an over flow (result is greater than 255). ? a div instruction causes a divide-by-zero condition. the ov bit is cleared to 0 by the add, addc, su bb, mul, and div instructions in all other cases. bit1: f1: user flag 1. this is a bit-addressable, general purpos e flag for use under software control. bit0: parity: parity flag. this bit is set to logic 1 if the sum of the eight bits in the accumulator is odd and cleared if the sum is even. r/w r/w r/w r/w r/w r/w r/w r reset value cy ac f0 rs1 rs0 ov f1 parity 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xd0 rs1 rs0 register bank address 0 0 0 0x00 - 0x07 0 1 1 0x08 - 0x0f 1 0 2 0x10 - 0x17 1 1 3 0x18 - 0x1f
c8051f320/1 86 rev. 1.1 figure 9.7. acc: accumulator bits7-0: acc: accumulator. this register is the accumula tor for arithme tic operations. r/w r/w r/w r/w r/w r/w r/w r/w reset value acc.7 acc.6 acc.5 acc.4 acc.3 acc.2 acc.1 acc.0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xe0 figure 9.8. b: b register bits7-0: b: b register. this register serves as a second accumula tor for certain arithmetic operations. r/w r/w r/w r/w r/w r/w r/w r/w reset value b.7 b.6 b.5 b.4 b.3 b.2 b.1 b.0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xf0
c8051f320/1 rev. 1.1 87 9.3. interrupt handler the cip-51 includes an extended interrupt system supporting a total of 16 interrupt sources with two priority levels. the allocation of interrupt so urces between on-chip peripherals and extern al inputs pins varies according to the spe - cific version of the device. each interr upt source has one or more associated in terrupt-pending flag(s) located in an sfr. when a peripheral or external s ource meets a valid interrupt condition, the associated interrupt-pending flag is set to logic 1. if interrupts are enabled for the source, an interrupt request is generated when the interrupt-pending flag is set. as soon as execution of the current instruction is complete, th e cpu generates an lcall to a predetermined address to begin execution of an interrupt service routine (isr). each isr must end with an reti instruction, which returns pro - gram execution to the next instruction that would have b een executed if the interrupt request had not occurred. if interrupts are not enabled, the interrupt-pending flag is ignored by the hardware and program execution continues as normal. (the interrupt-pending flag is set to logic 1 regardless of the interrup t's enable/disable state.) each interrupt source can be individually enabled or disabled through the use of an associated interrupt enable bit in an sfr (ie-eie2). however, interrupts must first be gl obally enabled by setting the ea bit (ie.7) to logic 1 before the individual interrupt enables are recognized. setting the ea bit to logic 0 disables all inte rrupt sources regardless of the individual interrupt-enable settings. some interrupt-pending flags are automa tically cleared by the hardware when the cpu vectors to the isr. however, most are not cleared by the ha rdware and must be cleared by software befo re returning from the isr. if an interrupt- pending flag remains set after the cpu completes the retu rn-from-interrupt (reti) in struction, a new interrupt request will be generated immediately and the cpu will re-ent er the isr after the completi on of the next instruction. 9.3.1. mcu interrupt sources and vectors the mcu supports 16 interrupt sources. software can simulate an interrupt by setting any interrupt-pending flag to logic 1. if interrupts are enabled for the fl ag, an interrupt request will be generated and the cpu will vector to the isr address associated with the in terrupt-pending flag. mcu interrupt sources, a ssociated vector addre sses, priority order and control bits are summarized in table 9.4 on page 89 . refer to the datasheet section associated with a particular on-chip peripheral for information regarding valid interrupt c onditions for the peripheral and the behavior of its inter - rupt-pending flag(s).
c8051f320/1 88 rev. 1.1 9.3.2. external interrupts the /int0 and /int1 external interrupt s ources are configurable as active high or low, edge or level sensitive. the in0pl (/int0 polarity) and in1pl (/int1 polarity) bits in the it01cf register select act ive high or active low; the it0 and it1 bits in tcon ( section ?19.1. timer 0 and timer 1? on page 217 ) select level or edge sensitive. the table below lists the possible configurations. /int0 and /int1 are assigned to port pins as defined in the it01cf register (see figure 9.15 ). note that /int0 and /int0 port pin assignments are independent of any cro ssbar assignments. /int0 and /int1 will monitor their assigned port pins without disturbing the peripheral that wa s assigned the port pin via th e crossbar. to assign a port pin only to /int0 and/or /int 1, configure the crossbar to skip the selected pin(s). this is accomplished by setting the associated bit in register xbr0 (see section ?14.1. priority crossbar decoder? on page 129 for complete details on configuring the crossbar). ie0 (tcon.1) and ie1 (tcon.3) serve as the interrupt-pending flags for the /int0 and /int1 external interrupts, respectively. if an /int0 or /int1 external interrupt is configured as edge-sensitive, the corresponding interrupt- pending flag is automatically cleared by the hardware when the cpu vectors to the isr. when configured as level sensitive, the interrupt-pending flag remains logic 1 while th e input is active as defined by the corresponding polarity bit (in0pl or in1pl); the flag remains logic 0 while the in put is inactive. the external interrupt source must hold the input active until the interrupt request is recognized. it must then deactivate the interrupt request before execution of the isr completes or another interrupt request will be generated. 9.3.3. interrupt priorities each interrupt source can be individually programmed to one of two priority leve ls: low or high. a low priority inter - rupt service routine can be preempted by a high priority inte rrupt. a high priority interrupt cannot be preempted. each interrupt has an associated interrupt priority bit in an sfr (ip or eip2) used to configure its priority level. low prior - ity is the default. if two interrupts ar e recognized simultaneously, the interrupt with the higher priority is serviced first. if both interrupts have the same priority level, a fixed priority order is used to arbitrate, given in table 9.4 . 9.3.4. interrupt latency interrupt response time depends on the state of the cpu wh en the interrupt occurs. pending interrupts are sampled and priority decoded each system clock cy cle. therefore, the fastest possible re sponse time is 5 system clock cycles: 1 clock cycle to detect the interrupt and 4 clock cycles to complete the lcall to the isr. if an interrupt is pending when a reti is executed, a single instru ction is executed before an lcall is made to service the pending interrupt. therefore, the maximum response time for an interrupt (whe n no other interrupt is currently being serviced or the new interrupt is of greater priority) occurs when the cpu is performing an reti instruction followed by a div as the next instruction. in this case, the response time is 18 system clock cycles: 1 clock cycle to detect the interrupt, 5 clock cycles to execute the reti, 8 clock cycles to complete the div instruction and 4 clock cycles to execute the lcall to the isr. if the cpu is executing an is r for an interrupt with equal or higher priority, the new interrupt will not be serviced until the current is r completes, including the reti and following instruction. note that the cpu is stalled during flash write/e rase operations and us b fifo movx accesses (see section ?12.2. accessing usb fifo space? on page 114 ). interrupt service latency will be increased for interrupts occuring while the cpu is stalled. the latency for these situations will be determined by the standard interrupt service proce - dure (as described above) and the amount of time the cpu is stalled. it0 in0pl /int0 interrupt it1 in1pl /int1 interrupt 10 active low, edge sensitive 10 active low, edge sensitive 11 active high, edge sensitive 11 active high, edge sensitive 00 active low, level sensitive 00 active low, level sensitive 01 active high, level sensitive 01 active high, level sensitive
c8051f320/1 rev. 1.1 89 table 9.4. interrupt summary interrupt source interrupt vector priority order pending flag bit addressable? cleared by hw? enable flag priority control reset 0x0000 top none n/a n/a always enabled always highest external interrupt 0 (/int0) 0x0003 0 ie0 (tcon.1) y y ex0 (ie.0) px0 (ip.0) timer 0 overflow 0x000b 1 tf0 (tcon.5) y y et0 (ie.1) pt0 (ip.1) external interrupt 1 (/int1) 0x0013 2 ie1 (tcon.3) y y ex1 (ie.2) px1 (ip.2) timer 1 overflow 0x001b 3 tf1 (tcon.7) y y et1 (ie.3) pt1 (ip.3) uart0 0x0023 4 ri0 (scon0.0) ti0 (scon0.1) y n es0 (ie.4) ps0 (ip.4) timer 2 overflow 0x002b 5 tf2h (tmr2cn.7) tf2l (tmr2cn.6) y n et2 (ie.5) pt2 (ip.5) spi0 0x0033 6 spif (spi0cn.7) wcol (spi0cn.6) modf (spi0cn.5) rxovrn (spi0cn.4) y n espi0 (ie.6) pspi0 (ip.6) smb0 0x003b 7 si (smb0cn.0) y n esmb0 (eie1.0) psmb0 (eip1.0) usb0 0x0043 8 special n n eusb0 (eie1.1) pusb0 (eip1.1) adc0 window compare 0x004b 9 ad0wint (adc0cn.3) y n ewadc0 (eie1.2) pwadc0 (eip1.2) adc0 conversion complete 0x0053 10 ad0int (adc0cn.5) y n eadc0 (eie1.3) padc0 (eip1.3) programmable counter array 0x005b 11 cf (pca0cn.7) ccfn (pca0cn.n) y n epca0 (eie1.4) ppca0 (eip1.4) comparator0 0x0063 12 cp0fif (cpt0cn.4) cp0rif (cpt0cn.5) n n ecp0 (eie1.5) pcp0 (eip1.5) comparator1 0x006b 13 cp1fif (cpt1cn.4) cp1rif (cpt1cn.5) n n ecp1 (eie1.6) pcp1 (eip1.6) timer 3 overflow 0x0073 14 tf3h (tmr3cn.7) tf3l (tmr3cn.6) n n et3 (eie1.7) pt3 (eip1.7) vbus level 0x007b 15 n/a n/a n/a evbus (eie2.0) pvbus (eip2.0)
c8051f320/1 90 rev. 1.1 9.3.5. interrupt register descriptions the sfrs used to enable the interrupt sources and set their priority level are described below. refer to the datasheet section associated with a particular on-chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s). figure 9.9. ie: interrupt enable bit7: ea: enable all interrupts. this bit globally enables/disables all interrupts. it overrides the individual interrupt mask settings. 0: disable all interrupt sources. 1: enable each interr upt according to its i ndividual mask setting. bit6: espi0: enable serial periph eral interface ( spi0) interrupt. this bit sets the masking of the spi0 interrupts. 0: disable all spi0 interrupts. 1: enable interrupt requests generated by spi0. bit5: et2: enable timer 2 interrupt. this bit sets the masking of the timer 2 interrupt. 0: disable timer 2 interrupt. 1: enable interrupt requests generated by the tf2l or tf2h flags. bit4: es0: enable uart0 interrupt. this bit sets the masking of the uart0 interrupt. 0: disable uart0 interrupt. 1: enable uart0 interrupt. bit3: et1: enable timer 1 interrupt. this bit sets the masking of the timer 1 interrupt. 0: disable all timer 1 interrupt. 1: enable interrupt requests generated by the tf1 flag. bit2: ex1: enable external interrupt 1. this bit sets the masking of external interrupt 1. 0: disable external interrupt 1. 1: enable interrupt requests generated by the /int1 input. bit1: et0: enable timer 0 interrupt. this bit sets the masking of the timer 0 interrupt. 0: disable all timer 0 interrupt. 1: enable interrupt requests generated by the tf0 flag. bit0: ex0: enable external interrupt 0. this bit sets the masking of external interrupt 0. 0: disable external interrupt 0. 1: enable interrupt requests generated by the /int0 input. r/w r/w r/w r/w r/w r/w r/w r/w reset value ea espi0 et2 es0 et1 ex1 et0 ex0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xa8
c8051f320/1 rev. 1.1 91 figure 9.10. ip: interrupt priority bit7: unused. read = 1, write = don't care. bit6: pspi0: serial periph eral interface (spi0) inte rrupt prior ity control. this bit sets the priority of the spi0 interrupt. 0: spi0 interrupt set to low priority level. 1: spi0 interrupt set to high priority level. bit5: pt2: timer 2 interrupt priority control. this bit sets the priority of the timer 2 interrupt. 0: timer 2 interrupt set to low priority level. 1: timer 2 interrupts set to high priority level. bit4: ps0: uart0 interrupt priority control. this bit sets the priority of the uart0 interrupt. 0: uart0 interrupt set to low priority level. 1: uart0 interrupts set to high priority level. bit3: pt1: timer 1 interrupt priority control. this bit sets the priority of the timer 1 interrupt. 0: timer 1 interrupt set to low priority level. 1: timer 1 interrupts set to high priority level. bit2: px1: external interrupt 1 priority control. this bit sets the priority of the ex ternal interrupt 1 interrupt. 0: external interrupt 1 set to low priority level. 1: external interrupt 1 set to high priority level. bit1: pt0: timer 0 interrupt priority control. this bit sets the priority of the timer 0 interrupt. 0: timer 0 interrupt set to low priority level. 1: timer 0 interrupt set to high priority level. bit0: px0: external interrupt 0 priority control. this bit sets the priority of the ex ternal interrupt 0 interrupt. 0: external interrupt 0 set to low priority level. 1: external interrupt 0 set to high priority level. r/w r/w r/w r/w r/w r/w r/w r/w reset value - pspi0 pt2 ps0 pt1 px1 pt0 px0 10000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xb8
c8051f320/1 92 rev. 1.1 figure 9.11. eie1: extended interrupt enable 1 bit7: et3: enable timer 3 interrupt. this bit sets the masking of the timer 3 interrupt. 0: disable timer 3 interrupts. 1: enable interrupt requests generated by the tf3l or tf3h flags. bit6: ecp1: enable comparator1 (cp1) interrupt. this bit sets the masking of the cp1 interrupt. 0: disable cp1 interrupts. 1: enable interrupt requests generated by the cp1rif or cp1fif flags. bit5: ecp0: enable comparator0 (cp0) interrupt. this bit sets the masking of the cp0 interrupt. 0: disable cp0 interrupts. 1: enable interrupt requests generated by the cp0rif or cp0fif flags. bit4: epca0: enable programmable counter array (pca0) interrupt. this bit sets the masking of the pca0 interrupts. 0: disable all pca0 interrupts. 1: enable interrupt requests generated by pca0. bit3: eadc0: enable adc0 conversion complete interrupt. this bit sets the masking of the adc0 conversion complete interrupt. 0: disable adc0 conversion complete interrupt. 1: enable interrupt requests generated by the ad0int flag. bit2: ewadc0: enable window comparison adc0 interrupt. this bit sets the masking of adc0 window comparison interrupt. 0: disable adc0 window comparison interrupt. 1: enable interrupt requests generated by adc0 window compare flag (ad0wint). bit1: eusb0: enable usb0 interrupt. this bit sets the masking of the usb0 interrupt. 0: disable all usb0 interrupts. 1: enable interrupt requests generated by usb0. bit0: esmb0: enable smbus (smb0) interrupt. this bit sets the masking of the smb0 interrupt. 0: disable all smb0 interrupts. 1: enable interrupt requests generated by smb0. r/w r/w r/w r/w r/w r/w r/w r/w reset value et3 ecp1 ecp0 epca0 eadc0 ewadc0 eusb0 esmb0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xe6
c8051f320/1 rev. 1.1 93 figure 9.12. eip1: extended interrupt priority 1 bit7: pt3: timer 3 interrupt priority control. this bit sets the priority of the timer 3 interrupt. 0: timer 3 interrupts set to low priority level. 1: timer 3 interrupts set to high priority level. bit6: pcp1: comparator1 (cp1) interrupt priority control. this bit sets the priority of the cp1 interrupt. 0: cp1 interrupt set to low priority level. 1: cp1 interrupt set to high priority level. bit5: pcp0: comparator0 (cp0) interrupt priority control. this bit sets the priority of the cp0 interrupt. 0: cp0 interrupt set to low priority level. 1: cp0 interrupt set to high priority level. bit4: ppca0: programmable counter array (pca0) interrupt priority control. this bit sets the priority of the pca0 interrupt. 0: pca0 interrupt set to low priority level. 1: pca0 interrupt set to high priority level. bit3: padc0 adc0 conversion complete interrupt priority control. this bit sets the priority of the adc0 conversion complete interrupt. 0: adc0 conversion complete interrupt set to low priority level. 1: adc0 conversion complete interrupt set to high priority level. bit2: pwadc0: adc0 window comparator interrupt priority control. this bit sets the priority of the adc0 window interrupt. 0: adc0 window interrupt set to low priority level. 1: adc0 window interrupt set to high priority level. bit1: pusb0: usb0 interrupt priority control. this bit sets the priority of the usb0 interrupt. 0: usb0 interrupt set to low priority level. 1: usb0 interrupt set to high priority level. bit0: psmb0: smbus (smb0) interrupt priority control. this bit sets the priority of the smb0 interrupt. 0: smb0 interrupt set to low priority level. 1: smb0 interrupt set to high priority level. r/w r/w r/w r/w r/w r/w r/w r/w reset value pt3 pcp1 pcp0 ppca0 padc0 pwadc0 pusb0 psmb0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xf6
c8051f320/1 94 rev. 1.1 figure 9.13. eie2: extended interrupt enable 2 bits7-1: unused. read = 0000000b. write = don?t care. bit0: evbus: enable vbus level interrupt. this bit sets the masking of the vbus interrupt. 0: disable all vbus interrupts. 1: enable interrupt requests generated by vbus level sense. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - - - - evbus 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xe7 figure 9.14. eip2: extended interrupt priority 2 bits7-1: unused. read = 0000000b. write = don?t care. bit0: pvbus: vbus level interrupt priority control. this bit sets the priority of the vbus interrupt. 0: vbus interrupt set to low priority level. 1: vbus interrupt set to high priority level. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - - - - pvbus 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xf7
c8051f320/1 rev. 1.1 95 bit7: in1pl: /int1 polarity 0: /int1 input is active low. 1: /int1 input is active high. bits6-4: in1sl2-0: /int1 port pin selection bits these bits select which port pin is assigned to /int 1. note that this pin assignment is independent of the crossbar; /int1 will monitor the assigned port pin without disturbing the peripheral that has been assigned the port pin via the crossbar. the crossbar will not assign the port pin to a peripheral if it is configured to skip the selected pin (accomplished by setting to ?1? the corresponding bit in register p0skip). bit3: in0pl: /int0 polarity 0: /int0 interrupt is active low. 1: /int0 interrupt is active high. bits2-0: int0sl2-0: /int0 port pin selection bits these bits select which port pin is assigned to /int 0. note that this pin assignment is independent of the crossbar. /int0 will monitor the assigned port pin without disturbing the peripheral that has been assigned the port pin via the crossbar. the crossbar will not assign the port pin to a peripheral if it is configured to skip the selected pin (accomplished by setting to ?1? the corresponding bit in register p0skip). r/w r/w r/w r/w r/w r/w r/w r/w reset value in1pl in1sl2 in1sl1 in1sl0 in0pl in0sl2 in0sl1 in0sl0 00000001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xe4 note: refer to figure 19.4 for int0/1 edge- or level-sensitive interrupt selection. in1sl2-0 /int1 port pin 000 p0.0 001 p0.1 010 p0.2 011 p0.3 100 p0.4 101 p0.5 110 p0.6 111 p0.7 in0sl2-0 /int0 port pin 000 p0.0 001 p0.1 010 p0.2 011 p0.3 100 p0.4 101 p0.5 110 p0.6 111 p0.7 figure 9.15. it01cf: int0/int 1 configuration register
c8051f320/1 96 rev. 1.1 9.4. power management modes the cip-51 core has two software programmable power mana gement modes: idle and stop. idle mode halts the cpu while leaving the peripherals and clocks active. in stop mode, the cpu is halted , all interrupts, are inactive, and the internal oscillator is stopped (analog peri pherals remain in their selected states; th e external oscillator is not affected). since clocks are running in idle mode, power consumption is dependent upon the system clock frequency and the number of peripherals left in active mode before enteri ng idle. stop mode consumes the least power. figure 1.15 describes the power control register (pcon) used to control the cip-51's power management modes. although the cip-51 has idle and stop modes built in (as with any standard 8051 architecture), power management of the entire mcu is better accomplish ed through system clock and individual peripheral management. each analog peripheral can be disabled when not in use and placed in low power mode. digital pe ripherals, such as timers or serial buses, draw little power when they are not in use. turning off the oscillators lowers power consumption considerably; however a reset is required to restart the mcu. the internal oscillator can be placed in suspend mode (see section ?13. oscillators? on page 117 ). in suspend mode, the internal oscillator is stopped until a non-idle us b event is detected, or the vbus input signal matches the polarity selected by the vbpol bit in register reg0cn ( figure 8.5 on page 72 ). 9.4.1. idle mode setting the idle mode select bit (pcon. 0) causes the cip-51 to halt the cpu and enter idle mode as soon as the instruction that sets the bit completes execution. all intern al registers and memory maintain their original data. all analog and digital peripherals can remain active during idle mode. idle mode is terminated when an enabled interrupt is assert ed or a reset occurs. the asse rtion of an enabled interrupt will cause the idle mode selection bit (pcon.0) to be cl eared and the cpu to resume operation. the pending inter - rupt will be serviced and the next inst ruction to be executed after the return from interrupt (reti) will be the instruc - tion immediately following the one that set the idle mode select bit. if idle mode is terminated by an internal or external reset, the cip-51 performs a normal reset sequence and begins program execution at address 0x0000. if enabled, the watchdog timer (wdt) will eventually cause an internal wa tchdog reset and thereby terminate the idle mode. this feature prot ects the system from an unin tended permanent shutdown in the event of an inadvertent write to the pcon register. if this behavior is not desire d, the wdt may be disabled by software prior to entering the idle mode if the wdt was initially configured to allow this operation. this provides the opportunity for additional power savings, allowing the system to remain in the idle mode indefinitely, waiting for an external stimulus to wake up the system. refer to section ?10.6. pca watchdog timer reset? on page 102 for more information on the use and configuration of the wdt. 9.4.2. stop mode setting the stop mode select bit (pcon.1) causes the cip-51 to enter stop mode as soon as the inst ruction that sets the bit completes execution. in stop mode the internal oscillator, cpu, and all digital peripherals are stopped; the state of the external oscillator circuit is not affected. each analog peripheral (including the external oscillator circuit) may be shut down individually prior to entering stop mode. stop mode can only be terminated by an internal or external reset. on reset, the cip- 51 performs the normal reset sequence a nd begins program execution at address 0x0000. if enabled, the missing clock detector will cause an internal reset and th ereby terminate the st op mode. the missing clock detector should be disabled if the cpu is to be put to in stop mode for longer than the mcd timeout of 100 sec.
c8051f320/1 rev. 1.1 97 bits7-2: gf5-gf0: general purpose flags 5-0. these are general purpose flags for use under software control. bit1: stop: stop mode select. setting this bit will place the cip-51 in stop mode. this bit will always be read as 0. 1: cpu goes into stop mode (internal oscillator stopped). bit0: idle: idle mode select. setting this bit will place the cip-51 in idle mode. this bit will always be read as 0. 1: cpu goes into idle mode. (shuts off clock to cpu, but clock to timers, interrupts, serial ports, and analog peripheral s are still active.) r/w r/w r/w r/w r/w r/w r/w r/w reset value gf5 gf4 gf3 gf2 gf1 gf0 stop idle 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x87 figure 9.16. pcon: power control register
c8051f320/1 98 rev. 1.1 notes
c8051f320/1 rev. 1.1 99 10. reset sources reset circuitry allows the controller to be easily placed in a predefined default co ndition. on entry to this reset state, the following occur: ? cip-51 halts program execution ? special function registers (sfrs) are initialized to their defined reset values ? external port pins are forced to a known state ? interrupts and timers are disabled. all sfrs are reset to the predefined valu es noted in the sfr detailed descriptions. the contents of internal data mem - ory are unaffected during a reset; any pr eviously stored data is preserved. ho wever, since the stack pointer sfr is reset, the stack is effectively lost even though the data on the stack is not altered. the port i/o latches are reset to 0xff (all logic ones) in open-drain mode. weak pull-ups are enabled during and after the reset. for vdd monitor and power-on resets, the /rst pin is driven low until the device exits the reset state. on exit from the reset state, the program counter (pc) is rese t, and the system clock defaults to the internal oscillator. refer to section ?13. oscillators? on page 117 for information on selecting and configuring the system clock source. the watchdog timer is enabled with the system clock divided by 12 as its clock source ( section ?20.3. watchdog timer mode? on page 246 details the use of the watchdog timer). program execution begins at location 0x0000. pca wdt missing clock detector (one- shot) software reset (swrsf) system reset reset funnel px.x px.x en system clock cip-51 microcontroller core extended interrupt handler clock select en wdt enable mcd enable errant flash operation + - comparator 0 c0rsef /rst (wired-or) power on reset + - vdd supply monitor enable '0' internal oscillator xtal1 xtal2 external oscillator drive clock multiplier usb controller vbus transition enable figure 10.1. reset sources
c8051f320/1 100 rev. 1.1 10.1. power-on reset during power-up, the device is held in a reset state an d the /rst pin is driven low until vdd settles above v rst . a power-on reset delay (t pordelay ) occurs before the device is released from reset; this delay is typically less than 0.3 ms. figure 10.2 . plots the power-on and vdd monitor reset timing. on exit from a power-on reset, the pors f flag (rstsrc.1) is set by hardware to logic 1. when por sf is set, all of the other reset flags in the rstsrc register are indeterminat e (porsf is cleared by all other resets). since all resets cause program execution to begin at the same location (0x000 0) software can read the po rsf flag to determine if a power-up was the cause of reset. the c ontent of internal data memory should be assumed to be undefined after a power-on reset. the vdd monitor is enabled following a power-on reset. software can force a power-on reset by writing ?1? to the pinrsf bit in register rstsrc. power-on reset vdd monitor reset /rst t volts 1.0 2.0 logic high logic low t pordelay v d d 2.70 2.4 v rst vdd figure 10.2. power-on and vdd monitor reset timing
c8051f320/1 rev. 1.1 101 10.2. power-fail reset / vdd monitor when a power-down transition or power irregularity causes vdd to drop below v rst , the power supply monitor will drive the /rst pin low and hold the cip-51 in a reset state (see figure 10.2 ). when vdd returns to a level above v rst , the cip-51 will be released from the reset state. note that even though internal data memory contents are not altered by the power-fail reset, it is impossible to determin e if vdd dropped below the level required for data reten - tion. if the porsf flag reads ?1?, the data may no longer be valid. the vdd monitor is enabled after power-on resets; however its defined state (enabled/disabled) is not altered by any other reset source. for example, if the vdd monitor is enabled and a software reset is performed, the vdd monitor will still be enabled after the reset. important note: the vdd monitor must be enabled before it is selected as a reset source. selecting the vdd moni - tor as a reset source before it is enabled and stabilized will cause a system reset. the procedure for configuring the vdd monitor as a reset source is shown below: step 1. enable the vdd monitor (vdm0cn.7 = ?1?). step 2. wait for the vdd monitor to stabilize (see table 10.1 for the vdd monitor turn-on time). step 3. select the vdd monitor as a reset source (rstsrc.1 = ?1?). see figure 10.2 for vdd monitor timing. see table 10.1 for complete electrical charact eristics of the vdd monitor. figure 10.3. vdm0cn: vdd monitor control bit7: vdmen: vdd monitor enable. this bit turns the vdd monitor circuit on/off. the vdd monitor cannot generate system resets until it is also selected as a reset source in register rstsrc (figure 10.4). the vdd monitor must be allowed to stabilize before it is selected as a reset source. selecting the vdd mo nitor as a reset source before it has stabilized will generate a system reset. see table 10.1 for the minimum vdd monitor turn-on time. the vdd monitor is enabled following all por resets. 0: vdd monitor disabled. 1: vdd monitor enabled. bit6: vddstat: vdd status. this bit indicates the current power supply status (vdd monitor output). 0: vdd is at or below the vdd monitor threshold. 1: vdd is above the vdd monitor threshold. bits5-0: reserved. read = variable. write = don?t care. r/wrrrrrrrreset value vdmen vddstat reserved reserved reserved reserved reserved reserved variable bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xff
c8051f320/1 102 rev. 1.1 10.3. external reset the external /rst pin provides a means for external circuitry to force the de vice into a reset state. asserting an active-low signal on the /rst pin generates a reset; an external pull-up and/or decoupling of the /rst pin may be necessary to avoid erroneous noise-induced resets. see table 10.1 for complete /rst pin specifications. the pinrsf flag (rstsrc.0) is set on exit from an external reset. 10.4. missing clock detector reset the missing clock detector (mcd) is a one-shot circuit that is triggered by the system clock. if more than 100 s pass between rising edges on the system clock, the one-shot wi ll time out and generate a reset. after a mcd reset, the mcdrsf flag (rstsrc.2) will read ?1?, signifying the mcd as the reset source; otherwis e, this bit reads ?0?. writ - ing a ?1? to the mcdrsf bit enables the missing clock detector; writing a ?0? disables it. the state of the /rst pin is unaffected by this reset. 10.5. comparator0 reset comparator0 can be configured as a reset source by wr iting a ?1? to the c0rsef fl ag (rstsrc.5). comparator0 should be enabled and allowed to settle prior to writing to c0rsef to prevent any turn-on chatter on the output from generating an unwanted reset. the comp arator0 reset is active-low: if the no n-inverting input voltage (on cp0+) is less than the inverting input voltage (on cp0-), a system re set is generated. after a co mparator0 reset, the c0rsef flag (rstsrc.5) will read ?1? signifying comparator0 as the reset source; otherw ise, this bit reads ?0?. the state of the /rst pin is unaffected by this reset. 10.6. pca watchdog timer reset the programmable watchdog timer (wdt) function of the programmable counter array (pca) can be used to pre - vent software from running out of control during a system malfunction. the pca wdt function can be enabled or disabled by software as described in section ?20.3. watchdog timer mode? on page 246 ; the wdt is enabled and clocked by sysclk / 12 following any reset. if a system malfunct ion prevents user software from updating the wdt, a reset is generated and the wdtrsf bit (rstsrc.5) is set to ?1?. the state of the /rst pin is unaffected by this reset. 10.7. flash error reset if a flash read/write/erase or program read targets an illegal address, a syst em reset is generated. this may occur due to any of the following: ? a flash write or erase is attempted above user code space. this o ccurs when pswe is set to ?1? and a movx write operation is attempted above address 0x3dff. ? a flash read is attempted above user code space. th is occurs when a movc operation is attempted above address 0x3dff. ? a program read is attempted above user code space. this occurs when user co de attempts to branch to an address above 0x3dff. ? a flash read, write or erase attempt is re stricted due to a flas h security setting (see section ?11.3. security options? on page 109 ). the ferror bit (rstsrc.6) is set following a flash error re set. the state of the /rst pin is unaffected by this reset.
c8051f320/1 rev. 1.1 103 10.8. software reset software may force a reset by writing a ?1? to the swrsf bit (rstsrc.4). the swrsf bit will read ?1? following a software forced reset. the state of th e /rst pin is unaffected by this reset. 10.9. usb reset writing ?1? to the usbrsf bit in register rstsrc selects us b0 as a reset source. with usb0 selected as a reset source, a system reset will be generated when either of th e following occur: 1. reset signaling is detected on the usb network. the usb function controller (usb0) must be enabled for reset signaling to be detected. see section ?15. universal serial bus controller (usb0)? on page 143 for information on the usb function controller. 2. the voltage on the vbus pin matches the polarity selected by the vbpol bit in register reg0cn. see section ?8. voltage regulator (reg0)? on page 67 for details on the vbus detection circuit. the usbrsf bit will read ?1? following a usb reset. the state of the /rst pin is unaffected by this reset.
c8051f320/1 104 rev. 1.1 f i gure 10 . 4 . r s t s r c : reset s ource reg i ster bit7: usbrsf: usb reset flag 0: read: last reset was not a usb reset; write: usb resets disabled. 1: read: last reset was a usb reset; write: usb resets enabled. bit6: ferror: flas h error indicator. 0: source of last reset was not a flash read/write/erase error. 1: source of last reset was a flash read/write/erase error. bit5: c0rsef: comparator0 reset enable and flag. 0: read: source of last reset was not comparator0; write: comparator0 is not a reset source. 1: read: source of last reset was comparator0; write: comparator0 is a rese t source (active-low). bit4: swrsf: software reset force and flag. 0: read: source of last reset was not a write to the swrsf bit; write: no effect. 1: read: source of last was a write to the swrsf bit; write: forces a system reset. bit3: wdtrsf: watchdog timer reset flag. 0: source of last reset was not a wdt timeout. 1: source of last reset was a wdt timeout. bit2: mcdrsf: missing clock detector flag. 0: read: source of last reset was not a missing clock detector timeout; write: missing clock detector disabled. 1: read: source of last reset was a missing clock detector timeout; write: missing clock detector enabled; triggers a reset if a missing clock condition is detected. bit1: porsf: power-on / vdd monitor reset flag. this bit is set anytime a power-on reset occurs. writing this bit selects/deselects the vdd monitor as a reset source. note: writing ?1? to this bit before the vdd monitor is enable d and stabilized can cause a system reset. see register vdm0cn (figure 10.3). 0: read: last reset was not a power-on or vdd monitor reset; write: vdd monitor is not a reset source. 1: read: last reset was a power-on or vdd monitor reset; all other reset flags indeterminate; write: vdd monitor is a reset source. bit0: pinrsf: hw pin reset flag. 0: source of last reset was not /rst pin. 1: source of last reset was /rst pin. note: for bits that act as both reset source enables (o n a write) and reset indicato r flags (on a read), read- modify-write instructions read and modify the source enable only. this applies to bits: usbrsf, c0rsef, swrsf, mcdrsf, porsf. r/w r r/w r/w r r/w r/w r reset value usbrsf ferror c0rsef swrsf wdtrsf mcdrsf porsf pinrsf variable bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xef
c8051f320/1 rev. 1.1 105 table 10.1. reset electrical characteristics -40c to +85c unless otherwise specified. parameter conditions min typ max units /rst output low voltage i ol = 8.5 ma, vdd = 2.7 v to 3.6 v 0.6 v /rst input high voltage 0.7 x vdd v /rst input low voltage 0.3 x vdd /rst input pull-up current /rst = 0.0 v 25 40 a vdd por threshold (v rst ) 2.40 2.55 2.70 v missing clock detector timeout time from last system clock rising edge to reset initiation 100 220 500 s reset time delay delay between release of any reset source and code execution at location 0x0000 5.0 s minimum /rst low time to generate a system reset 15 s vdd monitor turn-on time 100 s vdd monitor supply current 20 50 a
c8051f320/1 106 rev. 1.1 notes
c8051f320/1 rev. 1.1 107 11. flash memory on-chip, re-programmable flash memory is included for program code and non-volatile data storage. the flash memory can be programmed in-system, a single byte at a time, through the c2 interface or by software using the movx instruction. once cleared to logic 0, a flash bit must be erased to set it back to logic 1. flash bytes would typically be erased (set to 0xff) before being reprogramm ed. the write and erase operat ions are automatically timed by hardware for proper execution; data polling to determine th e end of the write/erase oper ation is not required. code execution is stalled during a flash write/erase operation. refer to table 11.1 for complete flash memory electri - cal characteristics. 11.1. programming the flash memory the simplest means of programming the flash memory is through the c2 interface using programming tools pro - vided by silicon labs or a third party vendor. this is th e only means for programming a non-initialized device. for details on the c2 commands to program flash memory, see section ?21. c2 interface? on page 253 . to ensure the integrity of flash contents, it is strongly recommende d that the on-chip vdd monitor be enabled in any system that includ es code that writes and/or erases flash memory from software. 11.1.1. flash lock and key functions flash writes and erases by user soft ware are protected with a lock and key function. the flash lock and key register (flkey) must be written with the correct key codes, in sequence, before flash operations may be per - formed. the key codes are: 0xa5, 0xf1. the timing does not matter, but the codes must be written in order. if the key codes are written out of order, or the wrong codes are written , flash writes and erases will be disabled until the next system reset. flash writes and erases will also be disabled if a flash write or erase is attempted before the key codes have been written properly. the flash lock resets after each write or erase; th e key codes must be written again before a following flash operation can be performed. the flkey register is detailed in figure 11.3 . 11.1.2. flash erase procedure the flash memory can be programmed by software using the movx write instruction with the address and data byte to be programmed provided as normal operands. be fore writing to flash memory using movx, flash write operations must be enabled by: (1) writing the flash key codes in sequence to the flash lock register (flkey); and (2) setting the pswe program store write enable bit ( psctl.0) to logic 1 (this directs the movx writes to tar - get flash memory). the pswe bit remains set until cleared by software. a write to flash memory can cl ear bits to logic 0 but cannot set them; only an erase operation can set bits to logic 1 in flash. a byte location to be programmed must be erased before a new value is written. the flash mem - ory is organized in 512-byte pages. the erase operation applie s to an entire page (setting all bytes in the page to 0xff). to erase an entire 512-byte page, perform the following steps: step 1. disable interrupts (recommended). step 2. write the first key code to flkey: 0xa5. step 3. write the second key code to flkey: 0xf1. step 4. set the psee bit (register psctl). step 5. set the pswe bit (register psctl). step 6. using the movx instructio n, write a data byte to any location within the 512-byte page to be erased. step 7. clear the pswe bit (register psctl). step 8. clear the psee bit (register pscti).
c8051f320/1 108 rev. 1.1 11.1.3. flash write procedure flash bytes are programm ed by software with the following sequence: step 1. disable interrupts (recommended). step 2. erase the 512-byte flash page cont aining the target location, as described in section 11.1.2 . step 3. write the first key code to flkey: 0xa5. step 4. write the second key code to flkey: 0xf1. step 5. set the pswe bit (register psctl). step 6. clear the psee bit (register psctl). step 7. using the movx instructio n, write a single data byte to the desired location within the 512-byte sector. step 8. clear the pswe bit (register psctl). steps 3-8 must be repeated for each byte to be written. after flash writes are complete, pswe should be cleared so that movx instructions do not target program memory. table 11.1. flash electrical characteristics parameter conditions min typ max units flash size c8051f320/1 16384 ? bytes endurance 20k 100k erase/write erase cycle time 25 mhz system clock 10 15 20 ms write cycle time 25 mhz system clock 40 55 70 s ? note: 512 bytes at location 0x3e00 to 0x3fff are reserved.
c8051f320/1 rev. 1.1 109 11.2. non-volatile data storage the flash memory can be used for non-vol atile data storage as well as program code. this allows data such as cal - ibration coefficients to be calculated a nd stored at run time. data is written using the movx write instruction and read using the movc instruction. note: movx read instructions always target xram. 11.3. security options the cip-51 provides security options to protect the flash memory from inadvertent modification by software as well as to prevent the viewing of pr oprietary program code and constants. the program store write enable (bit pswe in register psctl) and the prog ram store erase enable (bit psee in re gister psctl) bits protect the flash memory from accidental modification by software. pswe must be explicitly set to ?1? before software can modify the flash memory; both pswe and psee must be set to ?1 ? before software can erase flash memory. additional security features prevent propr ietary program code and data constants from being read or altered across the c2 inter - face. a security lock byte located at the last byte of flash user space offe rs protection of the flash program memory from access (reads, writes, or erases) by unprotected code or the c2 inte rface. the flash s ecurity mechanism allows the user to lock n 512-byte flash pages, starting at page 0 (addresses 0x0000 to 0x01ff), where n is the 1?s compliment number represented by the security lock byte. see example below. important notes about the flash security: 1. clearing any bit of the lock byte to ?0? will lo ck the flash page containing the lock byte (in addi - tion to the selected pages). 2. locked pages cannot be read, writte n, or erased via the c2 interface. 3. locked pages cannot be read, written, or erased by user firmware executing from unlocked memory space. 4. user firmware executing in a locked page may read and write flash memory in any locked or unlocked page excluding the reserved area. 5. user firmware executing in a locked page may eras e flash memory in any lo cked or unlocked page excluding the reserved area and th e page containing the lock byte. 6. locked pages can only be unlocked through th e c2 interface with a c2 device erase command. 7. if a user firmware flash access attempt is denied (per restrictions #3, #4, and #5 above), a flash error system reset will be generated. security lock byte: 11111 101b 1?s compliment: 00000010b flash pages locked: 2 addresses locked: 0x0000 to 0x03ff
c8051f320/1 110 rev. 1.1 access limit set according to the flash security lock byte c8051f320/1 0x0000 0x3dff lock byte reserved 0x3dfe 0x3e00 flash memory organized in 512-byte pages 0x3c00 unlocked flash pages locked when any other flash pages are locked figure 11.1. flash program memory map and security byte bits7-3: unused: read = 00000b. write = don?t care. bit2: reserved. read = 0b. must write = 0b. bit1: psee: program store erase enable setting this bit (in combination with pswe) allows an entire page of flash program memory to be erased. if this bit is logic 1 and flash writes are enabled (psw e is logic 1), a write to flash memory using the movx instruction will erase the entire page that contai ns the location addressed by the movx instruction. the value of the data byte written does not matter. 0: flash program memory erasure disabled. 1: flash program memory erasure enabled. bit0: pswe: program store write enable setting this bit allows writing a byte of data to the flash program memory using the movx write instruction. the flash location should be erased before writing data. 0: writes to flash program memory disabled. 1: writes to flash program memory enabled; the movx write instruction targets flash memory. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - - reserved psee pswe 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x8f figure 11.2. psctl: program store r/w control
c8051f320/1 rev. 1.1 111 figure 11.3. flkey: flash lock and key register bits7-0: flkey: flash lock and key register write: this register must be written to before flash writes or erases can be performed. flash remains locked until this register is written to with th e following key codes: 0xa5, 0xf1. the timing of the writes does not matter, as long as the codes are written in order. the key codes must be written for each flash write or erase operation. flash will be locked until the next system reset if the wrong codes are written or if a flash operation is attemp ted before the codes have been written correctly. read: when read, bits 1-0 indicate the current flash lock state. 00: flash is write/erase locked. 01: the first key code has been written (0xa5). 10: flash is unlocked (writes/erases allowed). 11: flash writes/er ases disabled until the next reset. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xb7 figure 11.4. flscl: flash scale register bits7: fose: flash one-shot enable this bit enables the flash read one-shot. when the flash one-shot disabled, the flash sense amps are enabled for a full clock cycle during fl ash reads. at system clock frequencies below 10 mhz, disabling the flash one-shot will increase system power consumption. 0: flash one-shot disabled. 1: flash one-shot enabled. bits6-0: reserved. read = 0. must write 0. r/w r/w r/w r/w r/w r/w r/w r/w reset value fose reserved reserved reserved reserved reserved reserved reserved 10000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xb6
c8051f320/1 112 rev. 1.1 notes
c8051f320/1 rev. 1.1 113 12. external ram the c8051f320/1 devices include 2048 bytes of on-chip xram. this xram space is split into user ram (addresses 0x0000 - 0x03ff) and usb0 fifo space (addresses 0x0400 - 0x07ff). 12.1. accessing user xram xram can be accessed using the external move instruc tion (movx) and the data poin ter (dptr), or using movx indirect addressing mode. if the movx in struction is used with an 8-bit a ddress operand (such as @r1), then the high byte of the 16-bit address is provided by the external memory interface control register (emi0cn as shown in figure 12.3 ). note: the movx instruction is also used for writes to the flash memory. see section ?11. flash memory? on page 107 for details. the movx instruction accesses xram by default. for any of the addressing modes the upper 5 bits of the 16 -bit external data memory address word are "don't cares". as a result, the 2048-byte ram is mapped modulo style over th e entire 64k external data memory address range. for example, the xram byte at address 0x0000 is al so at address 0x0800, 0x1000, 0x1800, 0x2000, etc. important note: the upper 1k of the 2k xram functions as usb fifo space. see section 12.2 for details on accessing this memory space. xram 1024 bytes 0x0000 0x03ff same 2048 bytes as from 0x0000 to 0x07ff, wrapped on 2k-byte boundaries 0x0400 0xffff usb fifos 1024 bytes 0x07ff 0x0800 accessed through usb fifo registers accessed with the movx instruction figure 12.1. external ram memory map
c8051f320/1 114 rev. 1.1 12.2. accessing usb fifo space the upper 1k of xram functions as usb fifo space. figure 12.2 shows an expanded view of the fifo space and user xram. fifo space is accessed via usb fifo registers; see section ?15.5. fifo management? on page 151 for more information on accessing these fifos. the movx instruction should not be used to load or modify usb data in the fifo space. unused areas of the fifo space may be used as general purpose xram, accessible as described in section 12.1 . the fifo block operates on the usb clock domain; thus the usb cloc k must be active when accessing fifo space. note that the number of sysclk cycles required by the movx instruction is increased when accessing usb fifo space. important note: the usb clock must be active when accessing fifo space. endpoint0 (64 bytes) free (64 bytes) 0x0400 0x043f 0x0440 0x063f 0x0640 0x073f 0x0740 0x07bf 0x07c0 0x07ff user xram (1024 bytes) 0x0000 0x03ff endpoint1 (128 bytes) endpoint2 (256 bytes) endpoint3 (512 bytes) usb fifo space (usb clock domain) user xram space (system clock domain) figure 12.2. xram memory map expanded view
c8051f320/1 rev. 1.1 115 figure 12.3. emi0cn: external memory interface control bits7-3: not used - reads 00000b. bits2-0: pgsel[2:0]: xram page select bits. the xram page select bits provide the high byte of the 16-bit external data memory address when using an 8-bit movx command, eff ectively selecting a 256-byte page of ram. the upper 5-bits are "don't cares", so the 2k address blocks are repeated modulo over the entire 64k external data memory address space. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - - pgsel2 pgsel1 pgsel0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xaa
c8051f320/1 116 rev. 1.1 notes
c8051f320/1 rev. 1.1 117 13. oscillators c8051f320/1 devices include a programmable internal oscillator, an external oscillator drive circuit, and a 4x clock multiplier. the internal oscillator can be enabled/disabled and calibrated us ing the oscicn and oscicl registers, as shown in figure 13.1 . the system clock (sysclk) can be derived from the internal oscillator , external oscillator circuit, or the 4x clock multiplier divided by 2. the usb clock (usbclk) can be derive d from the internal oscilla - tor, external oscillator, or 4x clock multiplier . oscillator electrical sp ecifications are given in table 13.3 on page 126 . 13.1. programmable internal oscillator all c8051f320/1 devices include a programmable internal osci llator that defaults as the system clock after a system reset. the internal oscillator period can be pr ogrammed via the oscicl register as defined by equation 13.1 , where f base is the frequency of the internal oscillator following a reset, ? t is the change in internal oscillator period, and ? oscicl is a change to the value held in register oscicl. figure 13.1. oscillator diagram clock multiplier osc exosc input circuit xtlvld xtal1 xtal2 option 2 vdd xtal2 option 1 10m ? option 3 xtal2 option 4 xtal2 oscxcn xtlvld xoscmd2 xoscmd1 xoscmd0 xfcn2 xfcn1 xfcn0 clkmul mulen mulinit mulrdy mulsel1 mulsel0 programmable internal clock generator en oscicl oscicn ioscen ifrdy suspend ifcn1 ifcn0 iosc n exosc / 2 x 2 x 2 exosc iosc sysclk exosc exosc / 2 exosc / 3 exosc / 4 iosc / 2 usbclk usbclk2-0 clksel usbclk2 usbclk1 usbclk0 clksl1 clksl0 equation 13.1. typical change in intern al oscillator period with oscicl ? t 0.0025 1 f base ------------ - ? oscicl ?
c8051f320/1 118 rev. 1.1 on c8051f320/1 devices, oscicl is factory calibrated to obtain a 12 mhz base frequency ( f base ). section 13.1.1 details oscillator programming for c8051f320/1 devices. electri cal specifications for the pr ecision internal oscillator are given in table 13.3 on page 126 . note that the system clock may be derived from the programmed internal oscil - lator divided by 1, 2, 4, or 8, as defined by the ifcn bits in register oscicn. the divide value defaults to 8 follow - ing a reset. 13.1.1. programming the internal oscillator on c8051f320/1 devices the oscicl reset value is factory calibrated to result in a 12 mhz internal oscillator with a 1.5% accuracy; this fre - quency is suitable for use as the usb clock (see section 13.4 ). software may modify the frequency of the internal oscillator as described below. important note: once the internal oscillator frequency has been modi fied, the internal oscillat or may not be used as the usb clock as described in section 13.4 . the internal oscillator frequency will reset to its original factory-cali - brated frequency following any device reset, at which po int the oscillator is suitable for use as the usb clock. software should read and adjust the value of oscicl according to equation 13.1 to obtain the desired frequency. the example below shows how to obtain an 11.6 mhz internal osc illator frequency. important note: if the sum of the reset value of oscicl and ? oscicl is greater than 31 or less than 0, then the device will not be capable of producing the desired frequency. 13.1.2. internal oscillator suspend mode the internal oscillator may be placed in suspend mode by writing ?1? to the suspend bit in register oscicn. in suspend mode, the internal oscillator is stopped until a non-idle usb event is detected ( section 15 ) or vbus matches the polarity selected by the vbpol bit in register reg0cn ( section 8.2 ). note that the usb transceiver must be enabled for a us b event to be detected. f base is the internal oscillator reset frequency; t base is the reset oscillator period. f des is the desired internal oscillator frequency; t des is the desired oscillator period. the required change in period ( ? t des ) is the difference between the ba se period and the desired period. using equation 13.1 and the above calculations, find ? oscicl : ? oscicl is rounded to the nearest integer (14) and added to the reset value of register oscicl. f base 12000000 hz = t base 1 12000000 ------------- ---------- - s = f des 11600000 hz = t des 1 11600000 ------------- ---------- - s = ? t des 1 11600000 --------------- -------- - 1 12000000 ------------- ---------- - ? 2.87 10 9 ? s == 2.87 10 9 ? 0.0025 1 f base ------------ - ? oscicl = ? oscicl 13.79 =
c8051f320/1 rev. 1.1 119 figure 13.2. oscicn: internal oscillator control register bit7: ioscen: internal oscillator enable bit. 0: internal oscillator disabled. 1: internal oscillator enabled. bit6: ifrdy: internal oscillator frequency ready flag. 0: internal oscillator is not running at programmed frequency. 1: internal oscillator is running at programmed frequency. bit5: suspend: force suspend writing a ?1? to this bit will force the internal oscillator to be stopped. the oscillator will be re-started on the next non-idle usb event (i.e ., resume signaling) or vbus interrupt event (see figure 8.5). bits4-2: unused. read = 000b, write = don't care. bits1-0: ifcn1-0: internal oscillator frequency control bits. 00: sysclk derived from internal oscillator divided by 8. 01: sysclk derived from internal oscillator divided by 4. 10: sysclk derived from internal oscillator divided by 2. 11: sysclk derived from internal oscillator divided by 1. r/w r r/w r r/w r/w r/w r/w reset value ioscen ifrdy suspend - - - ifcn1 ifcn0 00010100 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xb2 figure 13.3. oscicl: internal os cillator calibration register bits4-0: osccal: oscillator calibration value these bits determine the internal os cillator period as per equation 13.1. note: the contents of this register are unde fined when clock recovery is enabled. see section ?15.4. usb clock configuration? on page 150 for details on clock recovery. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - osccal variable bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xb3
c8051f320/1 120 rev. 1.1 13.2. external oscillator drive circuit the external oscillator circui t may drive an external crystal, ceramic re sonator, capacitor, or rc network. a cmos clock may also provide a clock input. for a crystal or ceram ic resonator configuration, the crystal/resonator must be wired across the xtal1 and xtal2 pins as shown in option 1 of figure 13.1 . a 10 m ? resistor also must be wired across the xtal1 and xtal2 pins for th e crystal/resonator configuration. in rc, capacitor, or cmos clock config - uration, the clock source should be wired to the xtal2 pin as shown in option 2, 3, or 4 of figure 13.1 . the type of external oscillator must be selected in the oscxcn register, and the frequency control bits (xfcn) must be selected appropriately (see figure 13.4 ) important note on ext ernal oscillator usage: port pins must be configured when using the external oscillator cir - cuit. when the external oscillator drive circuit is enabled in crystal/resonator mo de, port pins p0.2 and p0.3 are used as xtal1 and xtal2 respectively. when the external oscill ator drive circuit is enable d in capacitor, rc, or cmos clock mode, port pin p0.3 is used as xtal2. the port i/o cr ossbar should be configured to skip the port pins used by the oscillator circuit; see section ?14.1. priority crossbar decoder? on page 129 for crossbar configuration. additionally, when using the external oscillator circuit in crystal/resonator, capacitor, or rc mode, the associated port pins should be configured as analog inputs . in cmos clock mode, the associated pin should be configured as a digital input . see section ?14.2. port i/o initialization? on page 131 for details on port input mode selection. 13.2.1. clocking timers directly through the external oscillator the external oscillator source divided by eight is a clock option for the timers ( section ?19. timers? on page 217 ) and the programmable counter array (pca) ( section ?20. programmable counter array (pca0)? on page 235 ). when the external oscillator is used to clock these peripherals, but is not us ed as the system clock, the external oscil - lator frequency must be less than or equal to the system cl ock frequency. in this configuration, the clock supplied to the peripheral (external oscillat or / 8) is synchronized with the system cloc k; the jitter associated with this synchroni - zation is limited to 0.5 system clock cycles. 13.2.2. external crystal example if a crystal or ceramic resonator is used as an external oscillator source for the mcu, the circuit should be configured as shown in figure 13.1 , option 1. the external oscillator frequency control value (xfcn) should be chosen from the crystal column of the table in figure 13.4 (oscxcn register). for example, a 12 mhz crystal requires an xfcn setting of 111b. when the crystal oscillator is first enabled, the oscillato r amplitude detection circuit requires a settling time to achieve proper bias. introducing a delay of 1 ms between enabling the oscillator and checking the xt lvld bit will prevent a premature switch to the external oscillator as the system clock. switching to the external oscillator before the crystal oscillator has stabilized can result in unpredictable behavior. the recommended procedure is: step 1. enable the external oscillator. step 2. wait at least 1 ms. step 3. poll for xtlvld => ?1?. step 4. switch the system cloc k to the external oscillator. important note on external crystals: crystal oscillator circuits are quite sensitive to pcb layout. the crystal should be placed as close as possible to the xtal pins on the device. the traces should be as short as possible and shielded with ground plane from any other traces which could introduce noise or interference.
c8051f320/1 rev. 1.1 121 13.2.3. external rc example if an rc network is used as an external oscillator source for the mcu, the circuit should be configured as shown in figure 13.1 , option 2. the capacitor shou ld be no greater than 100 pf; however for very sm all capacitors, the total capacitance may be dominated by parasitic capacitance in the pcb layout. to determine the required external oscil - lator frequency control value (xfcn) in the oscxcn register, first select the rc network value to produce the desired frequency of oscillation. if the frequency desired is 100 khz, let r = 246 k ? and c = 50 pf: f = 1.23( 10 3 ) / rc = 1.23 ( 10 3 ) / [ 246 * 50 ] = 0.1 mhz = 100 khz referring to the table in figure 13.4 , the required xfcn setting is 010b. programming xfcn to a higher setting in rc mode will improve frequency accuracy at an increased extern al oscillator supply current. 13.2.4. external capacitor example if a capacitor is used as an external oscillator for the mcu, the circui t should be configured as shown in figure 13.1 , option 3. the capacitor should be no greater than 100 pf; however for very small capacitors, the total capacitance may be dominated by parasitic capacitanc e in the pcb layout. to determine the required external oscillator fre - quency control value (xfcn) in the os cxcn register, select the capacitor to be used and find the frequency of oscillation from the equations below. assume vdd = 3.0 v and c = 50 pf: f = kf / ( c * vdd ) = kf / ( 50 * 3 ) mhz f = kf / 150 mhz if a frequency of roughly 150 khz is desired, select the k factor from the table in figure 13.4 as kf = 22: f = 22 / 150 = 0.146 mhz, or 146 khz therefore, the xfcn value to use in this example is 011b.
c8051f320/1 122 rev. 1.1 figure 13.4. oscxcn: external oscillator control register bit7: xtlvld: crystal oscillator valid flag. (read only when xoscmd = 11x.) 0: crystal oscillator is unused or not yet stable. 1: crystal oscillator is running and stable. bits6-4: xoscmd2-0: external oscillator mode bits. 00x: external oscillator circuit off. 010: external cmos clock mode. 011: external cmos clock mode with divide by 2 stage. 100: rc oscillator mode. 101: capacitor oscillator mode. 110: crystal oscillator mode. 111: crystal oscillator mode with divide by 2 stage. bit3: reserved. read = 0, write = don't care. bits2-0: xfcn2-0: external oscillator frequency control bits. 000-111: see table below: crystal mode (circuit from figure 13.1, option 1; xoscmd = 11x) choose xfcn value to match crystal or resonator frequency. rc mode (circuit from figure 13.1, option 2; xoscmd = 10x) choose xfcn value to match frequency range: f = 1.23(10 3 ) / (r * c) , where f = frequency of clock in mhz c = capacitor value in pf r = pull-up resistor value in k ? c mode (circuit from figure 13.1, option 3; xoscmd = 10x) choose k factor (kf) for the oscillation frequency desired: f = kf / (c * vdd) , where f = frequency of clock in mhz c = capacitor value the xtal2 pin in pf vdd = power supply on mcu in volts r r/w r/w r/w r r/w r/w r/w reset value xtlvld xoscmd2 xoscmd1 xoscmd0 - xfcn2 xfcn1 xfcn0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xb1 xfcn crystal (xoscmd = 11x) rc (x oscmd = 10x) c (xoscmd = 10x) 000 f 32khz f 25khz k factor = 0.87 001 32khz < f 84khz 25khz < f 50khz k factor = 2.6 010 84khz < f 225khz 50khz < f 100khz k factor = 7.7 011 225khz < f 590khz 100khz < f 200khz k factor = 22 100 590khz < f 1.5mhz 200khz < f 400khz k factor = 65 101 1.5mhz < f 4mhz 400khz < f 800khz k factor = 180 110 4mhz < f 10mhz 800khz < f 1.6mhz k factor = 664 111 10mhz < f 30mhz 1.6mhz < f 3.2mhz k factor = 1590
c8051f320/1 rev. 1.1 123 13.3. 4x clock multiplier the 4x clock multiplier allows a 12 mhz oscillator to generate the 48 mhz clock required for full speed usb com - munication (see section ?15.4. usb clock configuration? on page 150 ). a divided version of the multiplier out - put can also be used as the system clock. see section 13.4 for details on system clock and usb clock source selection. the 4x clock multiplier is configured via the clkmul register. the proced ure for configuring and enabling the 4x clock multiplier is as follows: 1. reset the multiplier by writing 0x00 to register clkmul. 2. select the multiplier input source via the mulsel bits. 3. enable the multiplier with the mulen bit (clkmul | = 0x80). 4. delay for >5 s. 5. initialize the multiplier with the mulinit bit (clkmul | = 0xc0). 6. poll for mulrdy => ?1?. important note: when using an external oscillator as the input to th e 4x clock multiplier, the external source must be enabled and stable before the multiplier is initialized. see section 13.4 for details on selecting an exter - nal oscillator source. figure 13.5. clkmul: clock multiplier control register bit7: mulen: clock multiplier enable 0: clock multiplier disabled. 1: clock multiplier enabled. bit6: mulinit: clock multiplier initialize this bit should be a ?0? when the clock multiplier is enabled. once enabled, writing a ?1? to this bit will initialize the clock multiplier. the mulrdy bit reads ?1? when the clock multiplier is stabi- lized. bit5: mulrdy: clock multiplier ready this read-only bit indicates the status of the clock multiplier. 0: clock multiplier not ready. 1: clock multiplier ready (locked). bits4-2: unused. read = 000b; write = don?t care. bits1-0: mulsel: clock multiplier input select these bits select the clock supplied to the clock multiplier. r/w r/w r r/w r/w r/w r/w r/w reset value mulen mulinit mulrdy - - - mulsel 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address 0xb9 mulsel selected clock 00 internal oscillator 01 external oscillator 10 external oscillator / 2 11 reserved
c8051f320/1 124 rev. 1.1 13.4. system and usb clock selection the internal oscillator requires little start-up time and ma y be selected as the system or usb clock immediately fol - lowing the oscicn write that enables the internal oscilla tor. external crystals and ceramic resonators typically require a start-up time before they are settled and ready for use. the crys tal valid flag (xtlvld in register oscxcn) is set to ?1? by hardware when the external oscillator is settled. to avoid reading a false xtlvld, in crystal mode software should delay at least 1 ms between enabling the ext ernal oscillator and checking xtlvld. rc and c modes typically require no startup time. 13.4.1. system clock selection the clksl[1:0] bits in register clks el select which oscillator source is us ed as the system clock. clksl[1:0] must be set to 01b for the system clock to run from the ex ternal oscillator; however the external oscillator may still clock certain peripherals (timers, pca, usb) when the internal oscillator is selected as the system clock. the system clock may be switched on-the-fly between the internal oscillator, external oscillator, and 4x clock multiplier so long as the selected oscillator is enabled and has settled. 13.4.2. usb clock selection the usbclk[2:0] bits in regi ster clksel select which osci llator source is used as the usb clock. the usb clock may be derived from the 4x clock multiplier output, a divided version of the internal oscillator, or a divided version of the external oscillator. note that the usb clock must be 48 mhz when operating usb0 as a full speed function; the usb clock must be 6 mhz when operating usb0 as a low speed function. see figure 13.6 for usb clock selec - tion options. some example usb clock configurations fo r full and low speed mode are given below: tab le 13.1. typical usb full speed clock settings internal oscillator clock signal input source sel ection register bit settings usb clock clock multiplier usbclk = 000b clock multiplier input internal oscillator ? mulsel = 00b internal oscillator divide by 1 ifcn = 11b external oscillator clock signal input source sel ection register bit settings usb clock clock multiplier usbclk = 000b clock multiplier input external oscillator mulsel = 01b external oscillator crystal oscillator mode 12 mhz crystal xoscmd = 110b xfcn = 111b ? clock recovery must be enabled for this configuration. table 13.2. typical usb low speed clock settings internal oscillator clock signal input source sel ection register bit settings usb clock internal oscillator / 2 usbclk = 001b internal oscillator divide by 1 ifcn = 11b external oscillator clock signal input source sel ection register bit settings usb clock external oscillator / 4 usbclk = 101b external oscillator crystal oscillator mode 24 mhz crystal xoscmd = 110b xfcn = 111b
c8051f320/1 rev. 1.1 125 figure 13.6. clksel: clock select register bit 7: unused. read = 0b; write = don?t care. bits6-4: usbclk2-0: usb clock select these bits select the clock supplied to usb0. when operating usb0 in full-speed mode, the selected clock should be 48 mhz. when operating usb0 in low-speed mode , the selected clock should be 6 mhz. bits3-2: unused. read = 00b; write = don?t care. bits1-0: clksl1-0: system clock select these bits select the system clock source. r/w r/w r/w r/w r/w r/w r/w r/w reset value - usbclk - - clksl 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address 0xa9 usbclk selected clock 000 4x clock multiplier 001 internal oscillator / 2 010 external oscillator 011 external oscillator / 2 100 external oscillator / 3 101 external oscillator / 4 110 reserved 111 reserved clksl selected clock 00 internal oscillator (as determined by the ifcn bits in register oscicn) 01 external oscillator 10 4x clock multiplier / 2 11 reserved
c8051f320/1 126 rev. 1.1 table 13.3. internal oscillator el ectrical characteristics -40c to +85c unless otherwise specified parameter conditions min typ max units internal oscillator frequency reset frequency 11.82 12 12.18 mhz internal oscillator supply current (from vdd) oscicn.7 = 1 450 a usb clock frequency ? full speed mode low speed mode 47.88 5.91 48 6 48.12 6.09 mhz ? applies only to external oscillator sources.
c8051f320/1 rev. 1.1 127 14. port input/output digital and analog resources are availa ble through 25 i/o pins (c8051f320) or 21 i/o pins (C8051F321). port pins are organized as shown in figure 14.1 . each of the port pins can be defined as general-purpose i/o (gpio) or analog input; port pins p0.0-p2.3 can be assigned to on e of the internal digital resources as shown in figure 14.3 . the designer has complete control over which functions are assigned, limited only by the number of physical i/o pins. this resource assignment flexibility is achieved through the us e of a priority crossbar decoder. note that the state of a port i/o pin can always be read in the corresponding port latch, regardless of the crossbar settings. the crossbar assigns the selected inte rnal digital resources to the i/o pins based on the priority decoder ( figure 14.3 and figure 14.4 ). the registers xbr0 and xbr1, defined in figure 14.5 and figure 14.6 , are used to select internal digital functions. all port i/os are 5 v tolerant (refer to figure 14.2 for the port cell circuit). the port i/o cells are conf igured as either push-pull or open-drain in the port output mode register s (pnmdout, where n = 0,1,2,3) . complete electrical spec - ifications for port i/o are given in table 14.1 on page 142 . figure 14.1. port i/o f unctional block diagram xbr0, xbr1, pnskip registers digital crossbar priority decoder 2 p0 i/o cells p0.0 p0.7 8 pnmdout, pnmdin registers uart (internal digital signals) highest priority lowest priority sysclk 2 smbus t0, t1 2 6 pca cp1 outputs 2 4 spi cp0 outputs 2 p1 i/o cells p1.0 p1.7 8 p2 i/o cells p2.0 p2.7 8 p3 i/o cells p3.0 1 (port latches) p0 (p0.0-p0.7) (p1.0-p1.7) (p2.0-p2.7) (p3.0) 8 8 8 8 p1 p2 p3 note: p2.4-p2.7 only available on the c8051f320
c8051f320/1 128 rev. 1.1 figure 14.2. port i/o cell block diagram gnd /port-outenable port-output push-pull vdd vdd /weak-pullup (weak) port pad analog input analog select port-input
c8051f320/1 rev. 1.1 129 14.1. priority crossbar decoder the priority crossbar decoder ( figure 14.3 ) assigns a priority to each i/o function, starting at the top with uart0. when a digital resource is selected, th e least-significant unassigned port pin is assigned to that resource (excluding uart0, which is always at pins 4 and 5). if a port pin is as signed, the crossbar skips that pin when assigning the next selected resource. additionally, the crossbar will skip port pins whose associated bits in the pnskip registers are set. the pnskip registers allow software to skip port pins that are to be used for analog input, dedicated functions, or gpio. important note on crossbar configuration: if a port pin is claimed by a peripheral without use of the crossbar, its corresponding pnskip bit should be set. this applies to p0.7 if vref is used, p0.3 and/or p0.2 if the external oscil - lator circuit is enabled, p0.6 if the adc is configured to use the external conversion start signal (cnvstr), and any selected adc or comparator in puts. the crossbar skips selected pins as if they were already assigned, and moves to the next unassigned pin. figure 14.3 shows the crossbar decoder priority with no port pins skipped (p0skip, p1skip, p2skip = 0x00); figure 14.4 shows the crossbar decoder priority with the xtal1 (p0.2) and xtal2 (p0.3) pins skipped (p0skip = 0x0c). figure 14.3. crossbar priority decoder with no pins skipped xtal1 xtal2 cnvstr vref 012345670123456701234567 sck miso mosi nss* *nss is only pinned out in 4-wire spi mode cp0 cp0a cp1 00000000000000000000 special function signals are not assigned by the crossbar. when these signals are enabled, the crossbar must be manually configured to skip their corresponding port pins. port pin potentially available to peripheral sf signals eci t0 t1 p0skip[0:7] p2skip[0:3] signals unavailable sf signals pin i/o tx0 rx0 sda scl p0 p2 cex3 cex4 p1skip[0:7] p1 cp1a cex2 cex0 cex1 sysclk
c8051f320/1 130 rev. 1.1 registers xbr0 and xbr1 are us ed to assign the digital i/o resources to th e physical i/o port pins. note that when the smbus is selected, the crossbar assigns both pins asso ciated with the smbus (sda and scl); when the uart is selected, the crossbar assign s both pins associated with the uart (tx and rx). uart0 pin assignments are fixed for bootloading purposes: uart tx0 is always assigned to p0.4; uart rx0 is always assigned to p0.5. standard port i/os appear contiguously after the prioritized functions have been assigned. important note: the spi can be operated in either 3-wire or 4-wi re modes, depending on the state of the nssmd1- nssmd0 bits in register spi0cn. according to the spi mode, the nss signal may or may not be routed to a port pin. figure 14.4. crossbar priority decoder with crystal pins skipped xtal1 xtal2 cnvstr vref 012345670123456701234567 sck miso mosi nss* *nss is only pinned out in 4-wire spi mode cp0 cp0a cp1 00110000000000000000 special function signals are not assigned by the crossbar. when these signals are enabled, the crossbar must be manually configured to skip their corresponding port pins. port pin potentially available to peripheral sf signals eci t0 t1 p0skip[0:7] p2skip[0:3] p1skip[0:7] sf signals pin i/o tx0 rx0 sda scl p0 p1 p2 cp1a cex3 cex4 signals unavailable cex2 cex0 cex1 sysclk
c8051f320/1 rev. 1.1 131 14.2. port i/o initialization port i/o initialization consists of the following steps: step 1. select the input mode (analog or digital) for all port pins, using the port input mode register (pnmdin). step 2. select the output mode (open-drain or push-p ull) for all port pins, using the port output mode register (pnmdout). step 3. select any pins to be skipped by the i/ o crossbar using the port skip registers (pnskip). step 4. assign port pins to desired peripherals (xbr0, xbr1). step 5. enable the crossbar (xbare = ?1?). all port pins must be configured as either analog or digita l inputs. any pins to be used as comparator or adc inputs should be configured as an analog inputs. when a pin is config ured as an analog input, its weak pull-up, digital driver, and digital receiver are disabled. this pr ocess saves power and reduces noise on the analog input. pins configured as digital inputs may still be used by analog peripherals; howev er this practice is not recomm ended. to configure a port pin for digital input, write ?0? to the corresponding bit in register pnmdout, and write ?1? to the corresponding port latch (register pn). additionally, all analog input pins should be configured to be skipped by the crossbar (accomplished by setting the associated bits in pnskip). port input mode is set in the pnmdin register, where a ?1? in dicates a digital input, and a ?0? indicates an analog input. all pins default to digital inputs on reset. see figure 14.8 for the pnmdin register details. the output driver characteristics of th e i/o pins are defined using the port output mode registers (pnmdout). each port output driver can be configured as either open drain or push-pull. this selection is required even for the digital resources selected in the xbrn registers, and is not auto matic. the only exception to this is the smbus (sda, scl) pins, which are configured as open-drain regardless of the pnmdout settings. when the weakpud bit in xbr1 is ?0?, a weak pull-up is enabled for all port i/o configur ed as open-drain. weakpud do es not affect the push-pull port i/o. furthermore, the w eak pull-up is turned off on an output that is driving a ?0? to avoid unnecessary power dissipation. registers xbr0 and xbr1 must be loaded with the appropriate values to select the digital i/o functions required by the design. setting the xbare bit in xbr1 to ?1? enables the crossbar. until the crossbar is enabled, the external pins remain as standard port i/o (in input mode), regardle ss of the xbrn register settings. for given xbrn register settings, one can determine the i/o pin-out using the priority decode table; as an alternative, the configuration wiz - ard utility of the silicon labs ide software will determin e the port i/o pin-assignments based on the xbrn register settings. important note: the crossbar must be enabled to use ports p0, p1 , and p2.0-p2.3 as standard port i/o in output mode. these port output drivers are disa bled while the crossbar is disabled. p2.4-p2.7 and p3.0 always function as standard gpio.
c8051f320/1 132 rev. 1.1 figure 14.5. xbr0: port i/o crossbar register 0 bit7: cp1ae: comparator1 asynchronous output enable 0: asynchronous cp1 unavailable at port pin. 1: asynchronous cp1 routed to port pin. bit6: cp1e: comparator1 output enable 0: cp1 unavailable at port pin. 1: cp1 routed to port pin. bit5: cp0ae: comparator0 asynchronous output enable 0: asynchronous cp0 unavailable at port pin. 1: asynchronous cp0 routed to port pin. bit4: cp0e: comparator0 output enable 0: cp0 unavailable at port pin. 1: cp0 routed to port pin. bit3: syscke: /sysclk output enable 0: /sysclk unavaila ble at port pin. 1: /sysclk output routed to port pin. bit2: smb0e: smbus i/o enable 0: smbus i/o unavailable at port pins. 1: smbus i/o routed to port pins. bit1: spi0e: spi i/o enable 0: spi i/o unavailable at port pins. 1: spi i/o routed to port pins. bit0: urt0e: uart i/o output enable 0: uart i/o unavailable at port pin. 1: uart tx0, rx0 routed to port pins p0.4 and p0.5. r/w r/w r/w r/w r/w r/w r/w r/w reset value cp1ae cp1e cp0ae cp0e syscke smb0e spi0e urt0e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xe1
c8051f320/1 rev. 1.1 133 figure 14.6. xbr1: port i/o crossbar register 1 bit7: weakpud: port i/o weak pull-up disable. 0: weak pull-ups enabled (except for ports whose i/o are configured as analog input or push-pull output). 1: weak pull-ups disabled. bit6: xbare: crossbar enable. 0: crossbar disabled; al l port drivers disabled. 1: crossbar enabled. bit5: t1e: t1 enable 0: t1 unavailable at port pin. 1: t1 routed to port pin. bit4: t0e: t0 enable 0: t0 unavailable at port pin. 1: t0 routed to port pin. bit3: ecie: pca0 external counter input enable 0: eci unavailable at port pin. 1: eci routed to port pin. bits2-0: pca0me: pca module i/o enable bits. 000: all pca i/o unavailable at port pins. 001: cex0 routed to port pin. 010: cex0, cex1 routed to port pins. 011: cex0, cex1, cex2 routed to port pins. 100: cex0, cex1, cex2, cex3 routed to port pins. 101: cex0, cex1, cex2, cex3, ce x4 routed to port pins. 110: reserved. 111: reserved. r/w r/w r/w r/w r/w r/w r/w r/w reset value weakpud xbare t1e t0e ecie pca0me 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xe2
c8051f320/1 134 rev. 1.1 14.3. general purpose port i/o port pins that remain unassigned by the crossbar and are not used by analog peripherals can be used for general pur - pose i/o. ports3-0 are accessed through corresponding special function registers (sfrs) that are both byte address - able and bit addressable. when writing to a port, the value written to the sfr is latched to maintain the output data value at each pin. when reading, the logic levels of the po rt's input pins are returned regardless of the xbrn settings (i.e., even when the pin is assigned to another signal by the crossb ar, the port register can always read its correspond - ing port i/o pin). the exception to this is the execution of the read-modify-write instru ctions. the read -modify-write instructions when operating on a port sfr are the following: anl, orl, xr l, jbc, cpl, inc, dec, djnz and mov, clr or setb, when the destination is an individual bit in a port sfr. for these instructions, the value of the register (not the pin) is read, m odified, and written back to the sfr.
c8051f320/1 rev. 1.1 135 figure 14.7. p0: port0 register bits7-0: p0.[7:0] write - output appears on i/o pins per crossbar registers (when xbare = ?1?). 0: logic low output. 1: logic high output (high impedance if corresponding p0mdout.n bit = 0). read - always reads ?0? if selected as analog input in register p0mdin. direc tly reads port pin when configured as digital input. 0: p0.n pin is logic low. 1: p0.n pin is logic high. r/w r/w r/w r/w r/w r/w r/w r/w reset value p0.7 p0.6 p0.5 p0.4 p0.3 p0.2 p0.1 p0.0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0x80 figure 14.8. p0mdin: port0 input mode register bits7-0: analog input configuration bits for p0.7-p0.0 (respectively). port pins configured as analog i nputs have their weak pull-up, digi tal driver, and digital receiver dis- abled. 0: corresponding p0.n pin is configured as an analog input. 1: corresponding p0.n pin is not configured as an analog input. r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xf1
c8051f320/1 136 rev. 1.1 figure 14.9. p0mdout: port0 output mode register bits7-0: output configuration bits fo r p0.7-p0.0 (respectively): ignored if corresponding bit in register p0mdin is logic 0. 0: corresponding p0.n output is open-drain. 1: corresponding p0.n output is push-pull. (note: when sda and scl appear on any of the port i/o, each are open-drain regardless of the value of p0mdout). r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xa4 figure 14.10. p0skip: port0 skip register bits7-0: p0skip[7:0]: port0 cr ossbar skip enable bits. these bits select port pins to be skipped by the cro ssbar decoder. port pins used as analog inputs (for adc or comparator) or used as special functions (vref input, external oscillator circuit, cnvstr input) should be skipped by the crossbar. 0: corresponding p0.n pin is not skipped by the crossbar. 1: corresponding p0.n pin is skipped by the crossbar. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xd4
c8051f320/1 rev. 1.1 137 figure 14.11. p1: port1 register bits7-0: p1.[7:0] write - output appears on i/o pins per crossbar registers (when xbare = ?1?). 0: logic low output. 1: logic high output (high impedance if corresponding p1mdout.n bit = 0). read - always reads ?0? if selected as analog input in register p1mdin. direc tly reads port pin when configured as digital input. 0: p1.n pin is logic low. 1: p1.n pin is logic high. r/w r/w r/w r/w r/w r/w r/w r/w reset value p1.7 p1.6 p1.5 p1.4 p1.3 p1.2 p1.1 p1.0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0x90 figure 14.12. p1mdin: port1 input mode register bits7-0: analog input configuration bits for p1.7-p1.0 (respectively). port pins configured as analog i nputs have their weak pull-up, digi tal driver, and digital receiver dis- abled. 0: corresponding p1.n pin is configured as an analog input. 1: corresponding p1.n pin is not configured as an analog input. r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xf2
c8051f320/1 138 rev. 1.1 figure 14.13. p1mdout: port1 output mode register bits7-0: output configuration bits fo r p1.7-p1.0 (respectively): ignored if corresponding bit in register p1mdin is logic 0. 0: corresponding p1.n output is open-drain. 1: corresponding p1.n output is push-pull. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xa5 figure 14.14. p1skip: port1 skip register bits7-0: p1skip[7:0]: port1 cr ossbar skip enable bits. these bits select port pins to be skipped by the cro ssbar decoder. port pins used as analog inputs (for adc or comparator) or used as special functions (vref input, external oscillator circuit, cnvstr input) should be skipped by the crossbar. 0: corresponding p1.n pin is not skipped by the crossbar. 1: corresponding p1.n pin is skipped by the crossbar. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xd5
c8051f320/1 rev. 1.1 139 figure 14.15. p2: port2 register bits7-0: p2.[7:0] write - output appears on i/o pins per crossbar registers (when xbare = ?1?). 0: logic low output. 1: logic high output (high impedance if corresponding p2mdout.n bit = 0). read - always reads ?0? if selected as analog input in register p2mdin. direc tly reads port pin when configured as digital input. 0: p2.n pin is logic low. 1: p2.n pin is logic high. note: p2.7-p2.4 only available on c8051f320 devices. writes to thes e ports do not require xbare = ?1?. r/w r/w r/w r/w r/w r/w r/w r/w reset value p2.7 p2.6 p2.5 p2.4 p2.3 p2.2 p2.1 p2.0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xa0 figure 14.16. p2mdin: port2 input mode register bits7-0: analog input configuration bits for p2.7-p2.0 (respectively). port pins configured as analog i nputs have their weak pull-up, digi tal driver, and digital receiver dis- abled. 0: corresponding p2.n pin is configured as an analog input. 1: corresponding p2.n pin is not configured as an analog input. note: p2.7-p2.4 only available on c8051f320 devices. r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xf3
c8051f320/1 140 rev. 1.1 figure 14.17. p2mdout: port2 output mode register bits7-0: output configuration bits fo r p2.7-p2.0 (respectively): ignored if corresponding bit in register p2mdin is logic 0. 0: corresponding p2.n output is open-drain. 1: corresponding p2.n output is push-pull. note: p2.7-p2.4 only available on c8051f320 devices. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xa6 figure 14.18. p2skip: port2 skip register bits7-4: unused. read = 0000b. write = don?t care. bits3-0: p2skip[3:0]: port2 cr ossbar skip enable bits. these bits select port pins to be skipped by the cro ssbar decoder. port pins used as analog inputs (for adc or comparator) or used as special functions (vref input, external oscillator circuit, cnvstr input) should be skipped by the crossbar. 0: corresponding p2.n pin is not skipped by the crossbar. 1: corresponding p2.n pin is skipped by the crossbar. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xd6
c8051f320/1 rev. 1.1 141 figure 14.19. p3: port3 register bits7-0: p3.[7:0] write - output appears on i/o pins. 0: logic low output. 1: logic high output (high impedance if corresponding p3mdout.n bit = 0). read - always reads ?0? if selected as analog input in register p3mdin. direc tly reads port pin when configured as digital input. 0: p3.n pin is logic low. 1: p3.n pin is logic high. r/w r/w r/w r/w r/w r/w r/w r/w reset value p3.7 p3.6 p3.5 p3.4 p3.3 p3.2 p3.1 p3.0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xb0 figure 14.20. p3mdin: port3 input mode register bits7-1: unused. read = 0000000b; write = don?t care. bit0: analog input configuration bit for p3.0. port pins configured as analog i nputs have their weak pull-up, digi tal driver, and digital receiver dis- abled. 0: corresponding p3.n pin is configured as an analog input. 1: corresponding p3.n pin is not configured as an analog input. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xf4
c8051f320/1 142 rev. 1.1 table 14.1. port i/o dc electrical characteristics vdd = 2.7 to 3.6v, -40c to +85c unless otherwise specified parameters conditions min typ max units output high voltage i oh = -3ma, port i/o push-pull i oh = -10a, port i/o push-pull i oh = -10ma, port i/o push-pull vdd-0.7 vdd-0.1 vdd-0.8 v output low voltage i ol = 8.5ma i ol = 10a i ol = 25ma 1.0 0.6 0.1 v input high voltage 2.0 v input low voltage 0.8 v input leakage current weak pull-up off weak pull-up on, v in = 0 v 25 1 50 a figure 14.21. p3mdout: port3 output mode register bits7-1: unused. read = 0000000b; write = don?t care. bit0: output configuration bit for p3.0; ignored if corresponding bit in register p3mdin is logic 0. 0: corresponding p3.n output is open-drain. 1: corresponding p3.n output is push-pull. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xa7
c8051f320/1 rev. 1.1 143 15. universal serial bus controller (usb0) c8051f320/1 devices include a complete full/low speed usb function for usb peripheral implementations?. the usb function controller (usb0) consists of a serial interface engine (s ie), usb transceiver (including matching resistors and configurable pull- up resistors), 1k fifo block, and clock reco very mechanism for crys tal-less operation. no external components are required. the usb function controller and tr ansceiver is universal serial bus specifi - cation 2.0 compliant. important note: this document assumes a comprehensive understanding of the usb protocol. terms and abbreviations used in this document are defined in the usb specification. we encourage you to review the latest version of the usb specification before proceeding. ? the c8051f320/1 cannot be used as a usb host device. transceiver serial interface engine (sie) usb fifos (1k ram) d+ d- vdd endpoint0 in/out endpoint1 in out endpoint2 in out endpoint3 in out data transfer control cip-51 core usb control, status, and interrupt registers figure 15.1. usb0 block diagram
c8051f320/1 144 rev. 1.1 15.1. endpoint addressing a total of eight endpoint pipes are available. the control endpoint (endpoint0) always functions as a bi-directional in/out endpoint. the other endpoints are implemented as three pairs of in/out endpoint pipes: 15.2. usb transceiver the usb transceiver is configured via the usb0xcn register shown in figure 15.2 . this configuration includes transceiver enable/disable, pull-up resi stor enable/disable, and device speed se lection (full or lo w speed). when bit speed = ?1?, usb0 operates as a full speed usb function, and the on-chip pull-up resistor (if enabled) appears on the d+ pin. when bit speed = ?0?, usb0 operates as a lo w speed usb function, and the on-chip pull-up resistor (if enabled) appears on the d- pin. bits4-0 of register usb0 xcn can be used for transceiver testing as described in figure 15.2 . the pull-up resistor is enabled only when vbus is present (see section ?8.2. vbus detection? on page 69 for details on vbus detection). important note: the usb clock should be active before the transceiver is enabled. table 15.1. endpoint addressing scheme endpoint associated pipes usb protocol address endpoint0 endpoint0 in 0x00 endpoint0 out 0x00 endpoint1 endpoint1 in 0x81 endpoint1 out 0x01 endpoint2 endpoint2 in 0x82 endpoint2 out 0x02 endpoint3 endpoint3 in 0x83 endpoint3 out 0x03
c8051f320/1 rev. 1.1 145 figure 15.2. usb0xcn: usb0 transceiver control bit7: pren: internal pull-up resistor enable the location of the pull-up resistor (d+ or d-) is determined by the speed bit. 0: internal pull-up resistor disabled (devi ce effectively detached from the usb network). 1: internal pull-up resi stor enabled when vbus is present (device att ached to the usb network). bit6: phyen: physical layer enable this bit enables/disables the usb0 physical layer transceiver. 0: transceiver disabled (suspend). 1: transceiver enabled (normal). bit5: speed: usb0 speed select this bit selects the usb0 speed. 0: usb0 operates as a low speed device. if enabled, the internal pull-up resistor appears on the d- line. 1: usb0 operates as a full speed device. if enabled, the internal pull-up resistor appears on the d+ line. bits4-3: phytst1-0: physical layer test these bits can be used to test the usb0 transceiver. bit2: dfrec: differential receiver the state of this bit indicates th e current differential value present on the d+ and d- lines when phyen = ?1?. 0: differential ?0? signaling on the bus. 1: differential ?1? signaling on the bus. bit1: dp: d+ signal status this bit indicates the curren t logic level of the d+ pin. 0: d+ signal currently at logic 0. 1: d+ signal currently at logic 1. bit0: dn: d- signal status this bit indicates the curren t logic level of the d- pin. 0: d- signal currently at logic 0. 1: d- signal currently at logic 1. r/w r/w r/w r/w r/w r r r reset value pren phyen speed phytst1 phytst0 dfrec dp dn 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xd7 phytst[1:0] mode d+ d- 00b mode 0: normal (non-test mode) x x 01b mode 1: differential ?1? forced 1 0 10b mode 2: differential ?0? forced 0 1 11b mode 3: single-ended ?0? forced 0 0
c8051f320/1 146 rev. 1.1 15.3. usb register access the usb0 controller re gisters listed in table 15.2 are accessed through two sfrs: usb0 address (usb0adr) and usb0 data (usb0dat). the usb0adr register selects whic h usb register is targeted by reads/writes of the usb0dat register. see figure 15.3 . endpoint control/status registers are acce ssed by first writing the usb register index with the target endpoint num - ber. once the target endpoint number is written to the index register, the contro l/status registers associated with the target endpoint may be accessed. see the ?indexed registers? section of table 15.2 for a list of endpoint control/sta - tus registers. important note: the usb clock must be active when accessing usb registers. usb controller fifo access index register endpoint0 control/ status registers endpoint1 control/ status registers endpoint2 control/ status registers endpoint3 control/ status registers common registers interrupt registers 8051 sfrs usb0adr usb0dat figure 15.3. usb0 register access scheme
c8051f320/1 rev. 1.1 147 figure 15.4. usb0adr: usb0 indirect address register bits7: busy: usb0 register read busy flag this bit is used during indirect us b0 register accesses. software should write ?1? to this bit to initiate a read of the usb0 register targeted by the us baddr bits (usb0adr.[5-0]). the target address and busy bit may be written in the same write to usb0adr. after busy is set to ?1?, hardware will clear busy when the targeted register data is ready in the usb0dat register. software should check busy for ?0? before writing to usb0dat. write: 0: no effect. 1: a usb0 indirect register read is initiate d at the address specified by the usbaddr bits. read: 0: usb0dat register data is valid. 1: usb0 is busy accessing an indirect regi ster; usb0dat register data is invalid. bit6: autord: usb0 register auto-read flag this bit is used for block fifo reads. 0: busy must be written manually fo r each usb0 indirect register read. 1: the next indirect register r ead will automatically be initiated when software reads usb0dat (usbaddr bits will not be changed). bits5-0: usbaddr: usb0 in direct register address these bits hold a 6-bit address used to indirectly access the usb0 core registers. table 15.2 lists the usb0 core registers and their indi rect addresses. reads and writes to usb0dat will target the regis- ter indicated by the usbaddr bits. r/w r/w r/w r/w r/w r/w r/w r/w reset value busy autord usbaddr 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x96
c8051f320/1 148 rev. 1.1 figure 15.5. usb0dat: usb0 data register this sfr is used to indirectly read and write us b0 registers. write procedure: 1. poll for busy (usb0adr.7) => ?0?. 2. load the target usb0 register address into the usbaddr bits in register usb0adr. 3. write data to usb0dat. 4. repeat (step 2 may be skipped when writing to the same usb0 register). read procedure: 1. poll for busy (usb0adr.7) => ?0?. 2. load the target usb0 register address into the usbaddr bits in register usb0adr. 3. write ?1? to the busy bit in register usb0adr (steps 2 and 3 can be performed in the same write). 4. poll for busy (usb0adr.7) => ?0?. 5. read data from usb0dat. 6. repeat from step 2 (step 2 may be skipped when reading the same usb0 register; step 3 may be skipped when the autord bit (usb0adr.6) is logic 1). r/w r/w r/w r/w r/w r/w r/w r/w reset value usb0dat 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x97 figure 15.6. index: usb0 e ndpoint index (usb register) bits7-4: unused. read = 0000b; write = don?t care. bits3-0: epsel: endpoint select these bits select which endpoint is target ed when indexed usb0 registers are accessed. r r r r r/w r/w r/w r/w reset value - - - - epsel 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x0e index target endpoint 0x0 0 0x1 1 0x2 2 0x3 3 0x4 - 0xf reserved
c8051f320/1 rev. 1.1 149 table 15.2. usb0 controller registers usb register name usb register address description page number interrupt registers in1int 0x02 endpoint0 and endpoints1-3 in interrupt flags 157 out1int 0x04 endpoints1-3 out interrupt flags 158 cmint 0x06 common usb interrupt flags 159 in1ie 0x07 endpoint0 and endpoints1-3 in interrupt enables 160 out1ie 0x09 endpoints1-3 out interrupt enables 160 cmie 0x0b common usb interrupt enables 161 common registers faddr 0x00 function address 153 power 0x01 power management 155 framel 0x0c frame number low byte 156 frameh 0x0d frame number high byte 156 index 0x0e endpoint index selection 148 clkrec 0x0f clock recovery control 150 fifon 0x20-0x23 endpoints0-3 fifos 152 indexed registers e0csr 0x11 endpoint0 control / status 164 eincsrl endpoint in control / status low byte 168 eincsrh 0x12 endpoint in control / status high byte 169 eoutcsrl 0x14 endpoint out control / status low byte 171 eoutcsrh 0x15 endpoint out control / status high byte 172 e0cnt 0x16 number of received byte s in endpoint0 fifo 165 eoutcntl endpoint out packet count low byte 172 eoutcnth 0x17 endpoint out packet count high byte 172
c8051f320/1 150 rev. 1.1 15.4. usb clock configuration usb0 is capable of communication as a full or low speed usb function. co mmunication speed is selected via the speed bit in sfr usb0xcn. when operating as a low speed function, the usb0 clock must be 6 mhz. when operating as a full speed function, the usb0 clock must be 48 mhz. clock options are described in section ?13. oscillators? on page 117 . the usb0 clock is selected via sfr clksel (see figure 13.6 on page 125 ). clock recovery circuitry uses th e incoming usb data stream to adjust the internal oscillator; this allows the internal oscillator (and 4x clock multiplier) to meet the requir ements for usb clock tolerance. clock recovery should be used in the following configurations: when operating usb0 as a low speed fu nction with clock recovery, software must write ?1? to the crlow bit to enable low speed clock recovery. clock recovery is typically not necessary in low speed mode. single step mode can be used to help the clock recovery circuitry to lock when high noise levels are present on the usb network. this mode is not required (or recommended) in typical usb environments. communication speed usb clock 4x clock multiplier input full speed 4x clock multiplier internal oscillator low speed internal oscillator / 2 n/a figure 15.7. clkrec: clock rec overy control (usb register) bit7: cre: clock recovery enable. this bit enables/disables the usb clock recovery feature. 0: clock recovery disabled. 1: clock recovery enabled. bit6: crssen: clock recovery single step. this bit forces the oscillator calibration into ?single-step? mode during clock recovery. 0: normal calibration mode. 1: single step mode. bit5: crlow: low speed clock recovery mode. this bit must be set to ?1? if clock recovery is used when operating as a low speed usb device. 0: full speed mode. 1: low speed mode. bits4-0: reserved. read = variable. must write = 1001b. r/w r/w r/w r/w r/w r/w r/w r/w reset value cre crssen crlow reserved 00001001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x0f
c8051f320/1 rev. 1.1 151 15.5. fifo management 1024 bytes of on-chip xram are used as fifo space for usb0. this fifo sp ace is split between endpoints0-3 as shown in figure 15.8 . fifo space allocated for endpoints1-3 is conf igurable as in, out, or both (split mode: half in, half out). 15.5.1. fifo split mode the fifo space for endpoints1-3 can be sp lit such that the upper half of the fi fo space is used by the in endpoint, and the lower half is used by the out endpoint. for exampl e: if the endpoint3 fifo is configured for split mode, the upper 256 bytes (0x0540 to 0x063f) are used by endpoint3 in and the lower 256 bytes (0x0440 to 0x053f) are used by endpoint3 out. if an endpoint fifo is not configured for split mode, that endpoint in/out pair?s fifos are combined to form a sin - gle in or out fifo. in this case only one direction of the end point in/out pair may be used at a time. the end - point direction (in/out) is determined by the dirsel bi t in the corresponding endpoint?s eincsrh register (see figure 15.23 ). 15.5.2. fifo double buffering fifo slots for endpoints1-3 can be configured for double-buffered mode. in this mode, the maximum packet size is halved and the fifo may contain two packets at a time. this mode is available for endpoints1-3. when an endpoint is configured for split mode, double buffering may be enab led for the in endpoint and/or the out endpoint. when endpoint0 (64 bytes) configurable as in, out, or both (split mode) free (64 bytes) 0x0400 0x043f 0x0440 0x063f 0x0640 0x073f 0x0740 0x07bf 0x07c0 0x07ff user xram (1024 bytes) 0x0000 0x03ff usb clock domain system clock domain endpoint1 (128 bytes) endpoint2 (256 bytes) endpoint3 (512 bytes) figure 15.8. usb fifo allocation
c8051f320/1 152 rev. 1.1 split mode is not enabled, double-buffering may be enabled for the entire endpoint fifo. see table 15.3 for a list of maximum packet sizes for each fifo co nfiguration. 15.5.3. fifo access each endpoint fifo is accessed through a corresponding fifon register. a r ead of an endpoint fifon register unloads one byte from the fifo; a write of an endpoint fi fon register loads one byte into the endpoint fifo. when an endpoint fifo is configured for split mode, a read of the endpoint fifon register unloads one byte from the out endpoint fifo; a write of the endpoint fifon regist er loads one byte into the in endpoint fifo. table 15.3. fifo configurations endpoint number split mode enabled? maximum in packet size (double buffer disabled / enabled) maximum out packet size (double buffer disabled / enabled) 0n/a 64 1 n 128 / 64 y 64 / 32 64 / 32 2 n 256 / 128 y 128 / 64 128 / 64 3 n 512 / 256 y 256 / 128 256 / 128 figure 15.9. fifon: usb0 endpoin t fifo access (u sb registers) usb addresses 0x20 - 0x23 provide access to the 4 pairs of endpoint fifos: writing to the fifo address loads data into the in fifo for the corresponding endpoint. reading from the fifo address unloads data from the out fifo for the corresponding endpoint. r/w r/w r/w r/w r/w r/w r/w r/w reset value fifodata 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x20 - 0x23 in/out endpoint fifo usb address 0 0x20 1 0x21 2 0x22 3 0x23
c8051f320/1 rev. 1.1 153 15.6. function addressing the faddr register holds the current usb0 function address. software should write the host-assigned 7-bit function address to the faddr register when received as part of a set_address command. a new address written to faddr will not take effect (usb0 will not respond to the new address) until the end of the current transfer (typically following the status phase of the set_address command transfer). the update bit (f addr.7) is set to ?1? by hardware when software writes a ne w address to the faddr register. hard ware clears the update bit when the new address takes effect as described above. figure 15.10. faddr: usb0 function address (usb register) bit7: update: function address update set to ?1? when software writes the faddr register. usb0 clears this bit to ?0? when the new address takes effect. 0: the last address written to faddr is in effect. 1: the last address written to faddr is not yet in effect. bits6-0: function address holds the 7-bit function address for usb0. this address should be written by software when the set_address standard device reque st is received on endpoint0. the new address takes effect when the device request completes. r r/w r/w r/w r/w r/w r/w r/w reset value update function address 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x00
c8051f320/1 154 rev. 1.1 15.7. function configuration and control the usb register power ( figure 15.11 ) is used to configure and control usb0 at the device level (enable/disable, reset/suspend/resume handling, etc.). usb reset: the usbrst bit (power.3) is set to ?1? by hardware when reset signaling is detected on the bus. upon this detection, the following occur: 1. the usb0 address is reset (faddr = 0x00). 2. endpoint fifos are flushed. 3. control/status registers are reset to 0x00 (e 0csr, eincsrl, eincsrh, eoutcsrl, eoutcsrh). 4. usb register index is reset to 0x00. 5. all usb interrupts (excluding the suspend interrupt ) are enabled and their co rresponding flags cleared. 6. a usb reset interrupt is generated if enabled. writing a ?1? to the usbrst bit will generate an asynchro nous usb0 reset. all usb registers are reset to their default values following this asynchronous reset. suspend mode: with suspend detection enabled (susen = ?1?) , usb0 will enter susp end mode when suspend signaling is detected on the bus. an interrupt will be generated if enabled (susinte = ?1?). the suspend interrupt service routine (isr) should perform appl ication-specific configuration tasks su ch as disabling appropriate peripher - als and/or configuring clock sources for low power modes. see section ?13. oscillators? on page 117 for more details on internal oscillator configuration, including the suspend mode feature of the internal oscillator. usb0 exits suspend mode when any of th e following occur: (1) resume signaling is detected or generated, (2) reset signaling is detected, or (3) a device or usb reset occurs. if suspended, the internal oscill ator will exit suspend mode upon any of the above listed events. resume signaling: usb0 will exit suspend mode if resume signaling is detected on the bus. a resume interrupt will be generated upon detection if enabled (resinte = ?1?). software may force a remote wakeup by writing ?1? to the resume bit (power.2). when forcing a remote wakeup, software should write resume = ?0? to end resume signaling 10-15 ms after the remote wakeup is initiated (resume = ?1?). iso update: when software writes ?1? to the isoup bit (power.7 ), the iso update function is enabled. with iso update enabled, new packets written to an iso in endpoin t will not be transmitted unt il a new start-of-frame (sof) is received. if the iso in endpoint receives an in to ken before a sof, usb0 will transmit a zero-length packet. when isoup = ?1?, iso update is enabled for all iso endpoints. usb enable: usb0 is disabled following a power-on-reset (p or). usb0 is enabled by clearing the usbinh bit (power.4). once written to ?0?, the usbinh can only be se t to ?1? by one of the following: (1) a power-on-reset (por), or (2) an asynchronous usb0 reset generate d by writing ?1? to the usbrst bit (power.3). software should perform all usb0 configuration before enabling usb0. the configuration sequence should be per - formed as follows: step 1. select and enable the usb clock source. step 2. reset usb0 by writing usbrst= ?1?. step 3. configure and enable the usb transceiver. step 4. perform any usb0 function configuration (interrupts, suspend detect). step 5. enable usb0 by writing usbinh = ?0?.
c8051f320/1 rev. 1.1 155 figure 15.11. power: usb0 power (usb register) bit7: isoud: iso update this bit affects all in isochronous endpoints. 0: when software writes inprdy = ?1?, usb0 wi ll send the packet when the next in token is received. 1: when software writes inprdy = ?1?, usb0 will wait for a sof token before sending the packet. if an in token is received be fore a sof token, us b0 will send a zero-le ngth data packet. bits6-5: unused. read = 00b. write = don?t care. bit4: usbinh: usb0 inhibit this bit is set to ?1? following a power-on reset (por) or an asynchronous usb0 reset (see bit3: reset). software should clear this bit after all usb0 and transceiver initialization is complete. soft- ware cannot set this bit to ?1?. 0: usb0 enabled. 1: usb0 inhibited. all usb traffic is ignored. bit3: usbrst: reset detect writing ?1? to this bit forces an asynchronous usb0 reset. reading this bit provides bus reset status information. read: 0: reset signaling is not present on the bus. 1: reset signaling detected on the bus. bit2: resume: force resume software can force resume signaling on the bus to wake usb0 from suspend mode. writing a ?1? to this bit while in suspend mode (susmd = ?1?) forces usb0 to generate resume signaling on the bus (a remote wakeup event). software should write resume = ?0? after 10 ms to15 ms to end the resume signaling. an interrupt is generated, and hardware clears susmd, when software writes resume = ?0?. bit1: susmd: suspend mode set to ?1? by hardware when usb0 enters suspend mode. cleared by hardware when software writes resume = ?0? (following a remote wakeup) or read s the cmint register after detection of resume signaling on the bus. 0: usb0 not in suspend mode. 1: usb0 in suspend mode. bit0: susen: suspend detection enable 0: suspend detection disabled. usb0 will ignore suspend signaling on the bus. 1: suspend detection enabled. usb0 will enter suspend mode if it detects suspend signaling on the bus. r/w r/w r/w r/w r/w r/w r r/w reset value isoud - - usbinh usbrst resume susmd susen 00010000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x01
c8051f320/1 156 rev. 1.1 figure 15.12. framel: usb0 fr ame number low (usb register) bits7-0: frame number low this register contains bits7-0 of the last received frame number. rrrrrrrrreset value frame number low 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x0c figure 15.13. frameh: usb0 frame number high (usb register) bits7-3: unused. read = 0. write = don?t care. bits2-0: frame number high byte this register contains bits10-8 of the last received frame number. rrrrrrrrreset value - - - - - frame number high 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x0d
c8051f320/1 rev. 1.1 157 15.8. interrupts the read-only usb0 interrupt flags are located in the usb registers shown in figure 15.14 through figure 15.16 . the associated interrupt enable bits are located in the usb registers shown in figure 15.17 through figure 15.19 . a usb0 interrupt is generated when any of the usb interrupt flags is set to ?1?. the usb0 interrupt is enabled via the eie1 sfr (see section ?9.3. interrupt handler? on page 87 ). important note: reading a usb int errupt flag register resets all fl ags in that register to ?0?. figure 15.14. in1int: usb0 in endpo int interrupt (usb register) bits7-4: unused. read = 0000b. write = don?t care. bit3: in3: in endpoint 3 interrupt-pending flag this bit is cleared when softwa re reads the in1int register. 0: in endpoint 3 interrupt inactive. 1: in endpoint 3 interrupt active. bit2: in2: in endpoint 2 interrupt-pending flag this bit is cleared when softwa re reads the in1int register. 0: in endpoint 2 interrupt inactive. 1: in endpoint 2 interrupt active. bit1: in1: in endpoint 1 interrupt-pending flag this bit is cleared when softwa re reads the in1int register. 0: in endpoint 1 interrupt inactive. 1: in endpoint 1 interrupt active. bit0: ep0: endpoint 0 interrupt-pending flag this bit is cleared when softwa re reads the in1int register. 0: endpoint 0 interrupt inactive. 1: endpoint 0 interrupt active. rrrrrrrrreset value - - - - in3 in2 in1 ep0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x02
c8051f320/1 158 rev. 1.1 figure 15.15. out1int: usb0 out endpoint interrupt (usb register) bits7-4: unused. read = 0000b. write = don?t care. bit3: out3: out endpoint 3 interrupt-pending flag this bit is cleared when softwa re reads the out1int register. 0: out endpoint 3 interrupt inactive. 1: out endpoint 3 interrupt active. bit2: out2: out endpoint 2 interrupt-pending flag this bit is cleared when softwa re reads the out1int register. 0: out endpoint 2 interrupt inactive. 1: out endpoint 2 interrupt active. bit1: out1: out endpoint 1 interrupt-pending flag this bit is cleared when softwa re reads the out1int register. 0: out endpoint 1 interrupt inactive. 1: out endpoint 1 interrupt active. bit0: unused. read = 0; write = don?t care. rrrrrrrrreset value - - - - out3 out2 out1 - 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x04
c8051f320/1 rev. 1.1 159 figure 15.16. cmint: usb0 common interrupt (usb register) bits7-4: unused. read = 0000b; write = don?t care. bit3: sof: start of frame interrupt set by hardware when a sof token is received. this interrupt event is synt hesized by hardware: an interrupt will be generated when hardware expects to receive a sof event, ev en if the actual sof sig- nal is missed or corrupted. this bit is cleared when soft ware reads the cmint register. 0: sof interrupt inactive. 1: sof interrupt active. bit2: rstint: reset interrupt-pending flag set by hardware when reset sign aling is detected on the bus. this bit is cleared when soft ware reads the cmint register. 0: reset interrupt inactive. 1: reset interrupt active. bit1: rsuint: resume interrupt-pending flag set by hardware when resume signaling is detected on the bus while usb0 is in suspend mode. this bit is cleared when soft ware reads the cmint register. 0: resume interrupt inactive. 1: resume interrupt active. bit0: susint: suspend interrupt-pending flag when suspend detection is enabled (bit susen in register power), this bit is set by hardware when suspend signaling is detected on the bus. this bit is cleared when software reads the cmint register. 0: suspend interrupt inactive. 1: suspend interrupt active. rrrrrrrrreset value - - - - sof rstint rsuint susint 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x06
c8051f320/1 160 rev. 1.1 figure 15.17. in1ie: usb0 in endpoint interrupt enable (usb register) bits7-4: unused. read = 0000b. write = don?t care. bit3: in3e: in endpoint 3 interrupt enable 0: in endpoint 3 interrupt disabled. 1: in endpoint 3 interrupt enabled. bit2: in2e: in endpoint 2 interrupt enable 0: in endpoint 2 interrupt disabled. 1: in endpoint 2 interrupt enabled. bit1: in1e: in endpoint 1 interrupt enable 0: in endpoint 1 interrupt disabled. 1: in endpoint 1 interrupt enabled. bit0: ep0e: endpoint 0 interrupt enable 0: endpoint 0 interrupt disabled. 1: endpoint 0 interrupt enabled. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - in3e in2e in1e ep0e 00001111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x07 figure 15.18. out1ie: usb0 out endpoint interrupt enable (usb register) bits7-4: unused. read = 0000b. write = don?t care. bit3: out3e: out endpoint 3 interrupt enable 0: out endpoint 3 interrupt disabled. 1: out endpoint 3 interrupt enabled. bit2: out2e: out endpoint 2 interrupt enable 0: out endpoint 2 interrupt disabled. 1: out endpoint 2 interrupt enabled. bit1: out1e: out endpoint 1 interrupt enable 0: out endpoint 1 interrupt disabled. 1: out endpoint 1 interrupt enabled. bit0: unused. read = 0; write = don?t? care. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - out3e out2e out1e - 00001110 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x09
c8051f320/1 rev. 1.1 161 15.9. the serial interface engine the serial interface engine (sie) performs all low level usb protocol tasks, in terrupting the processor when data has successfully been transmitted or received. when receiving da ta, the sie will interrupt th e processor when a complete data packet has been received; approp riate handshaking signals are automatica lly generated by the sie. when trans - mitting data, the sie will interrupt the processor when a co mplete data packet has been transmitted and the appropri - ate handshake signal has been received. the sie will not interrupt the processor when corr upted/erroneous packets are received. 15.10. endpoint0 endpoint0 is managed through the usb register e0csr ( figure 15.20 ). the index register must be loaded with 0x00 to access the e0csr register. an endpoint0 interrupt is generated when: 1. a data packet (out or setup) has been receiv ed and loaded into the endpoint0 fifo. the oprdy bit (e0csr.0) is set to ?1? by hardware. 2. an in data packet has successfully been unloaded from the endpoint0 fifo and transmitted to the host; inprdy is reset to ?0? by hardware. 3. an in transaction is completed (this interrupt generated during the status stage of the transaction). 4. hardware sets the ststl bit (e0c sr.2) after a control transaction ended due to a protocol violation. 5. hardware sets the suend bit (e0csr.4) because a control transfer ended before firmware sets the dataend bit (e0csr.3). the e0cnt register ( figure 15.21 ) holds the number of received da ta bytes in the endpoint0 fifo. figure 15.19. cmie: usb0 common in terrupt enable (usb register) bits7-4: unused. read = 0000b; write = don?t care. bit3: sofe: start of frame interrupt enable 0: sof interrupt disabled. 1: sof interrupt enabled. bit2: rstinte: reset interrupt enable 0: reset interrupt disabled. 1: reset interrupt enabled. bit1: rsuinte: resume interrupt enable 0: resume interrupt disabled. 1: resume interrupt enabled. bit0: susinte: suspend interrupt enable 0: suspend interrupt disabled. 1: suspend interrupt enabled. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - sofe rstinte rsuinte susinte 00000110 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x0b
c8051f320/1 162 rev. 1.1 hardware will automatically detect protocol errors and send a stall condition in response. firmware may force a stall condition to abort the current transf er. when a stall condition is generate d, the ststl bit will be set to ?1? and an interrupt generated. the following conditions will cause hardware to generate a stall condition: 1. the host sends an out token during a out data phase after the dataend bit has been set to ?1?. 2. the host sends an in token during an in data phase after the dataend bit has been set to ?1?. 3. the host sends a packet that exceeds the maximum packet size for endpoint0. 4. the host sends a non-zero length data1 packet during the status phase of an in transaction. firmware sets the sdstl bit (e0csr.5) to ?1?. 15.10.1.endpoint0 setup transactions all control transfers must begin with a setup packet. setup p ackets are similar to out packets, containing an 8-byte data field sent by the host. any setup packet containing a command field of anything other than 8 bytes will be automatically rejected by usb0. an endpoint0 interrupt is generated when the data from a setup packet is loaded into the endpoint0 fifo. software should unload the command from the endpoint0 fifo, decode the com - mand, perform any necessary tasks, an d set the soprdy bit to indicate th at it has serviced the out packet. 15.10.2.endpoint0 in transactions when a setup request is receive d that requires usb0 to tran smit data to the host, one or more in requests will be sent by the host. for the first in transaction, firmware shou ld load an in packet into the endpoint0 fifo, and set the inprdy bit (e0csr.1). an interrupt wi ll be generated when an in packet is transmitted successfully. note that no interrupt will be generated if an in request is received be fore firmware has loaded a p acket into the endpoint0 fifo. if the requested data exceeds the maximum packet size for endpoint0 (a s reported to the host), the data should be split into multiple packets; each packet shoul d be of the maximum packet size exclud ing the last (resi dual) packet. if the requested data is an integer multiple of the maximum packet size for endpoint0, the last data packet should be a zero-length packet signaling the end of the transfer. firm ware should set the dataend bit to ?1? after loading into the endpoint0 fifo the last data packet for a transfer. upon reception of the firs t in token for a particular contro l transfer, endpoint0 is said to be in transmit mode. in this mode, only in tokens should be sent by the host to endp oint0. the suend bit (e0csr.4) is set to ?1? if a setup or out token is received while e ndpoint0 is in transmit mode. endpoint0 will remain in transmit mode until any of the following occur: 1. usb0 receives an endpoi nt0 setup or out token. 2. firmware sends a packet less than the maximum endpoint0 packet size. 3. firmware sends a zero-length packet. firmware should set the dataend bit (e0csr.3) to ?1? when performing (2) and (3) above. the sie will transmit a nak in response to an in token if there is no packet ready in the in fifo (inprdy = ?0?).
c8051f320/1 rev. 1.1 163 15.10.3.endpoint0 out transactions when a setup request is received that requires the host to tr ansmit data to usb0, one or more out requests will be sent by the host. when an out pack et is successfully received by usb0 , hardware will set the oprdy bit (e0csr.0) to ?1? and generate an endpoint0 interrupt. fo llowing this interrupt, firmware should unload the out packet from the endpoint0 fifo and set the soprdy bit (e0csr.6) to ?1?. if the amount of data required for th e transfer exceeds the maximu m packet size for endpoint0, the data will be split into multiple packets. if the requested data is an intege r multiple of the maximum packet size for endpoint0 (as reported to the host), the host will send a zero-lengt h data packet signaling the end of the transfer. upon reception of the first out token for a particular control transf er, endpoint0 is said to be in receive mode. in this mode, only out tokens should be sent by the host to endpoint0. the suend bit (e0csr.4) is set to ?1? if a setup or in token is received wh ile endpoint0 is in receive mode. endpoint0 will remain in receive mode until: 1. the sie receives a setup or in token. 2. the host sends a packet less than the maximum endpoint0 packet size. 3. the host sends a zero-length packet. firmware should set the dataend bit (e 0csr.3) to ?1? when the expected amou nt of data has been received. the sie will transmit a stall condition if the host sends an out packet after the dataend bit has been set by firm - ware. an interrupt will be generated with the ststl b it (e0csr.2) set to ?1? after the stall is transmitted.
c8051f320/1 164 rev. 1.1 figure 15.20. e0csr: usb0 endpoin t0 control (usb register) bit7: ssuend: serviced setup end write: software should set this bit to ?1? after servicing a setup end (bit suend) event. hardware clears the suend bit when software writes ?1? to ssuend. read: this bit always reads ?0?. bit6: soprdy: serviced oprdy write: software should write ?1? to this bit after se rvicing a received endpoint0 packet. the oprdy bit will be cleared by a write of ?1? to soprdy. read: this bit always reads ?0?. bit5: sdstl: send stall software can write ?1? to this bit to terminate the current transfer (due to an error condition, unex- pected transfer request, etc.). ha rdware will clear this bit to ?0? when the stall handshake is trans- mitted. bit4: suend: setup end hardware sets this read-only bit to ?1? when a cont rol transaction ends before software has written ?1? to the dataend bit. hardware clears this bit when software writes ?1? to ssuend. bit3: dataend: data end software should write ?1? to this bit: 1. when writing ?1? to inprdy fo r the last outgoing data packet. 2. when writing ?1? to inprdy for a zero-length data packet. 3. when writing ?1? to soprdy after servicing the last incoming data packet. this bit is automatically cleared by hardware. bit2: ststl: sent stall hardware sets this bit to ?1? after transmitting a stall handshake signal. this flag must be cleared by software. bit1: inprdy: in packet ready software should write ?1? to this bit after loading a data packet into the endpoint0 fifo for transmit. hardware clears this bit and generates an interr upt under either of the following conditions: 1. the packet is transmitted. 2. the packet is overwritte n by an incoming setup packet. 3. the packet is overwritte n by an incoming out packet. bit0: oprdy: out packet ready hardware sets this read-only bit an d generates an interrupt when a data packet has been received. this bit is cleared only when software writes ?1? to the soprdy bit. r/w r/w r/w r r/w r/w r/w r reset value ssuend soprdy sdstl suend dataend ststl inprdy oprdy 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x11
c8051f320/1 rev. 1.1 165 figure 15.21. e0cnt: usb0 endpoint 0 data count (usb register) bit7: unused. read = 0; write = don?t care. bits6-0: e0cnt: endpoint 0 data count this 7-bit number indicates the number of received data bytes in the endpoint 0 fifo. this number is only valid while bit oprdy is a ?1?. rrrrrrrrreset value - e0cnt 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x16
c8051f320/1 166 rev. 1.1 15.11. configuring endpoints1-3 endpoints1-3 are configured and controlled through their own sets of the following control/status registers: in regis - ters eincsrl and eincsrh, and out registers eoutcsrl and eoutcsrh. only one set of endpoint control/ status registers is mapped into the us b register address space at a time, defi ned by the contents of the index regis - ter ( figure 15.6 ). endpoints1-3 can be configured as in, out, or both in/out (split mode) as described in section 15.5.1 . the end - point mode (split/normal) is selected via the split bit in register eincsrh. when split = ?1?, the corr esponding endpoint fifo is split, and both in and out pipes are available. when split = ?0?, the corresponding endpoint functions as either in or out; the endpoint direction is selected by the dirsel bit in register eincsrh. 15.12. controlling endpoints1-3 in endpoints1-3 in are managed via usb registers eincsrl and eincsrh. all in endpoints can be used for inter - rupt, bulk, or isochronous transfers. isochronous (iso) mode is enabled by wr iting ?1? to the iso bit in register eincsrh. bulk and interrupt transfers are handled identically by hardware. an endpoint1-3 in interrupt is genera ted by any of the following conditions: 1. an in packet is successfully transferred to the host. 2. software writes ?1? to the flush bit (eincsrl.3) when the target fifo is not empty. 3. hardware generates a stall condition. 15.12.1.endpoints1-3 in interrupt or bulk mode when the iso bit (eincsrh.6) = ?0? the target endpoint operates in bulk or interrupt mode. once an endpoint has been configured to operate in bulk /interrupt in mode (typically following an endpoint0 set_interface com - mand), firmware should load an in packet into the endpoint in fifo and set the inprdy bit (eincsrl.0). upon reception of an in token, hardware will transmit the data, clear the inpr dy bit, and generate an interrupt. writing ?1? to inprdy without writing any data to the endpoint fifo will cause a zero-length packet to be transmit - ted upon reception of the next in token. a bulk or interrupt pipe can be shut down (or halted) by writing ?1? to the sdstl bit (eincsrl.4). while sdstl = ?1?, hardware will respond to all in requests with a stall condition. each time hardware generates a stall condition, an interrupt will be generated and the st stl bit (eincsrl.5) set to ?1?. the ststl bit must be reset to ?0? by firmware. hardware will automatically reset inprdy to ?0? when a packet slot is open in the endpoint fifo. note that if dou - ble buffering is enabled for the target endpoint, it is possible for firmware to load two packets into the in fifo at a time. in this case, hardware will reset inprdy to ?0? immedi ately after firmware loads the first packet into the fifo and sets inprdy to ?1?. an interrupt will not be generated in this case; an interrupt will only be generated when a data packet is transmitted. when firmware writes ?1? to the fcdt bit (eincsrh.3), the data toggle for each in packet will be toggled continu - ously, regardless of the handshake receive d from the host. this feature is typi cally used by interrupt endpoints func - tioning as rate feedback communication for isochronous endpoi nts. when fcdt = ?0?, the data toggle bit will only be toggled when an ack is sent from th e host in response to an in packet.
c8051f320/1 rev. 1.1 167 15.12.2.endpoints1-3 in isochronous mode when the iso bit (eincsrh.6) is set to ?1?, the target endpoint operates in isochrono us (iso) mode. once an end - point has been configured for iso in mode, the host will send one in token (data request) per frame; the location of data within each frame may vary. because of this, it is recommended that do uble buffering be enabled for iso in endpoints. hardware will automatically reset inprdy (eincsrl.0) to ?0? when a packet slot is open in the endpoint fifo. note that if double buffering is enabled for the target endpoint, it is possible fo r firmware to load two packets into the in fifo at a time. in this case, hardware will reset inprdy to ?0? imme diately after firmware loads the first packet into the fifo and sets inprdy to ?1?. an interrupt will not be generated in this case; an interrupt will only be gener - ated when a data packet is transmitted. if there is not a data packet ready in the endpoint fifo when usb0 receives an in token from the host, usb0 will transmit a zero-length data packet and set the undrun bit (eincsrl.2) to ?1?. the iso update feature (see section 15.7 ) can be useful in starting a double buffered iso in endpoint. if the host has already set up the iso in pipe (has begun transmitting in tokens) when firmware writes the first data packet to the endpoint fifo, the next in token may arrive and the first data packet sent before firmware has written the second (double buffered) data packet to the fi fo. the iso update feature ensures that any data packet written to the end - point fifo will not be transmitted during the current frame; th e packet will only be sent after a sof signal has been received.
c8051f320/1 168 rev. 1.1 figure 15.22. eincsrl: usb0 in endpoint control high byte (usb register) bit7: unused. read = 0; write = don?t care. bit6: clrdt: clear data toggle. write: software should write ?1? to this bit to reset the in endpoint data toggle to ?0?. read: this bit always reads ?0?. bit5: ststl: sent stall hardware sets this bit to ?1? when a stall handshake signal is transmitted. the fifo is flushed, and the inprdy bit cleared. this flag must be cleared by software. bit4: sdstl: send stall. software should write ?1? to this bit to generate a stall handshake in response to an in token. soft- ware should write ?0? to this bit to terminate the stall signal. this bit has no effect in iso mode. bit3: flush: fifo flush. writing a ?1? to this bit flushes the next packet to be transmitted from the in endpoint fifo. the fifo pointer is reset and the inprdy bit is cleared. if the fifo contains mu ltiple packets, software must write ?1? to flush for each p acket. hardware resets the flush bit to ?0? when the fifo flush is complete. bit2: undrun: data underrun. the function of this bit depends on the in endpoint mode: iso: set when a zero-length packet is sent after an in token is received while bit inprdy = ?0?. interrupt/bulk: set when a nak is retu rned in response to an in token. this bit must be cleared by software. bit1: fifone: fifo not empty. 0: the in endpoint fifo is empty. 1. the in endpoint fifo contains one or more packets. bit0: inprdy: in packet ready. software should write ?1? to this bit after loading a data packet into the in endpoint fifo. hardware clears inprdy due to any of the following: 1. a data packet is transmitted. 2. double buffering is enabled (dbien = ?1 ?) and there is an open fifo packet slot. 3. if the endpoint is in isochronous mode (iso = ?1?) and isoud = ?1?, inprdy will read ?0? until the next sof is received. an interrupt (if enabled) will be generated when hardware clears inprdy as a result of a packet being transmitted. r w r/w r/w w r/w r/w r/w reset value - clrdt ststl sdstl flush undrun fifone inprdy 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x11
c8051f320/1 rev. 1.1 169 figure 15.23. eincsrh: usb0 in endpoint control low byte (usb register) bit7: dbien: in endpoint double-buffer enable. 0: double-buffering disabled fo r the selected in endpoint. 1: double-buffering enabled for the selected in endpoint. bit6: iso: isochronous transfer enable. this bit enables/disables isochronous transfers on the current endpoint. 0: endpoint configured for bulk/interrupt transfers. 1: endpoint configured for isochronous transfers. bit5: dirsel: endpoint direction select. this bit is valid only when the selected fifo is not split (split = ?0?). 0: endpoint direction selected as out. 1: endpoint direction selected as in. bit4: unused. read = ?0?. write = don?t care. bit3: fcdt: force data toggle. 0: endpoint data toggle switches only when an ac k is received following a data packet transmission. 1: endpoint data toggle forced to switch after every data packet is transmitted, regardless of ack reception. bit2: split: fifo split enable. when split = ?1?, the selected end point fifo is split. the upper half of the selected fifo is used by the in endpoint; the lower half of the selected fifo is used by the out endpoint. bits1-0: unused. read = 00b; write = don?t care. r/w r/w r/w r r/w r/w r r reset value dbien iso dirsel - fcdt split - - 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x12
c8051f320/1 170 rev. 1.1 15.13. controlling endpoints1-3 out endpoints1-3 out are managed via usb registers eoutcs rl and eoutcsrh. all out endpoints can be used for interrupt, bulk, or isochronous transf ers. isochronous (iso) mode is enabled by writing ?1? to the iso bit in reg - ister eoutcsrh. bulk and interrupt transf ers are handled identically by hardware. an endpoint1-3 out interrupt may be generated by the following: 1. hardware sets the oprdy bit (eincsrl.0) to ?1?. 2. hardware generates a stall condition. 15.13.1.endpoints1-3 out interrupt or bulk mode when the iso bit (eoutcsrh.6) = ?0? the target endpoint op erates in bulk or interrupt mode. once an endpoint has been configured to operate in bulk/interrupt out mode (typically following an endpoint0 set_interface com - mand), hardware will set the oprdy b it (eoutcsrl.0) to ?1 ? and generate an interrupt upon reception of an out token and data packet. the number of byte s in the current out data packet (the packet ready to be unloaded from the fifo) is given in the eoutcnth and eoutcntl registers. in response to this interrupt, firmware should unload the data packet from the out fifo and reset the oprdy bit to ?0?. a bulk or interrupt pipe can be shut down (or halted) by writing ?1? to the sdstl bit (eoutcsrl.5). while sdstl = ?1?, hardware will respond to all out requests with a stall condition. each time hardware generates a stall condition, an interrupt will be generated and the ststl bit (eoutcsrl.6) set to ?1?. the ststl bit must be reset to ?0? by firmware. hardware will automatically set oprdy when a packet is ready in the out fifo. note that if double buffering is enabled for the target endpoint, it is po ssible for two packets to be ready in the out fifo at a time. in this case, hard - ware will set oprdy to ?1? immediately after firmware unl oads the first packet and resets oprdy to ?0?. a second interrupt will be generated in this case. 15.13.2.endpoints1-3 out isochronous mode when the iso bit (eoutcsrh.6) is set to ?1?, the target endpoint operates in isochronous (iso) mode. once an end - point has been configured for iso out mode, the host will send exactly one data per us b frame; the location of the data packet within each frame may vary, however. because of this, it is recommende d that double buffering be enabled for iso out endpoints. each time a data packet is received, hardware will load the r eceived data packet into th e endpoint fifo, set the oprdy bit (eoutcsrl.0) to ?1?, and gene rate an interrupt (if enabled). firmware would typically use this interrupt to unload the data packet from the endpoint fifo and reset the oprdy bit to ?0?. if a data packet is received when there is no room in the endpoint fifo, an interrupt will be generated and the ovrun bit (eoutcsrl.2) set to ?1?. if usb0 receives an is o data packet with a crc erro r, the data packet will be loaded into the endpoint fifo, oprdy will be set to ?1?, an interrupt (if enabled) will be generated, and the dataerr bit (eoutcsrl.3) will be set to ?1?. software should ch eck the dataerr bit each time a data packet is unloaded from an iso out endpoint fifo.
c8051f320/1 rev. 1.1 171 figure 15.24. eoutcsrl: usb0 out endpoin t control high byte (usb register) bit7: clrdt: clear data toggle write: software should write ?1? to this bit to reset the out endpoint data toggle to ?0?. read: this bit always reads ?0?. bit6: ststl: sent stall hardware sets this bit to ?1? when a stall handshak e signal is transmitted. this flag must be cleared by software. bit5: sdstl: send stall software should write ?1? to this bit to generate a stall handshake. software should write ?0? to this bit to terminate the stall signal. this bit has no effect in iso mode. bit4: flush: fifo flush writing a ?1? to this bit flushes the next packet to be read from the out endpoint fifo. the fifo pointer is reset and the oprdy bit is cleared. if th e fifo contains multiple packets, software must write ?1? to flush for each packet. hardware resets the flush bit to ?0? when the fifo flush is complete. bit3: daterr: data error in iso mode, this bit is set by hardware if a recei ved packet has a crc or bit-stuffing error. it is cleared when software clears oprdy. this bit is only valid in iso mode. bit2: ovrun: data overrun this bit is set by hardware when an incoming data packet cannot be loaded into the out endpoint fifo. this bit is only valid in iso mode, and must be cleared by software. 0: no data overrun. 1: a data packet was lost because of a fu ll fifo since this flag was last cleared. bit1: fifoful: out fifo full this bit indicates the contents of the out fifo . if double buffering is enabled for the endpoint (dbien = ?1?), the fifo is full wh en the fifo contains tw o packets. if dbien = ?0?, the fifo is full when the fifo contains one packet. 0: out endpoint fifo is not full. 1: out endpoint fifo is full. bit0: oprdy: out packet ready hardware sets this bit to ?1? and generates an inte rrupt when a data packet is available. software should clear this bit after each data packet is unloaded from the out endpoint fifo. w r/w r/w w r r/w r r/w reset value clrdt ststl sdstl flush daterr ovrun fifoful oprdy 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x14
c8051f320/1 172 rev. 1.1 figure 15.25. eoutcsrh: usb0 out endpoi nt control low byte (usb register) bit7: dboen: double-buffer enable 0: double-buffering disabled for the selected out endpoint. 1: double-buffering enabled fo r the selected out endpoint. bit6: iso: isochronous transfer enable this bit enables/disables isochronous transfers on the current endpoint. 0: endpoint configured for bulk/interrupt transfers. 1: endpoint configured for isochronous transfers. bits5-0: unused. read = 000000b; write = don?t care. r/w r/w r/w r/w r r r r reset value dboen iso -- - - - - 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x15 figure 15.26. eoutcntl: usb0 out en dpoint count low (usb register) bits7-0: eocl: out endpoint count low byte eocl holds the lower 8-bits of th e 10-bit number of data bytes in the last received packet in the cur- rent out endpoint fifo. this number is only valid while oprdy = ?1?. rrrrrrrrreset value eocl 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x16 figure 15.27. eoutcnth: usb0 out e ndpoint count high (usb register) bits7-2: unused. read = 00000. write = don?t care. bits1-0: eoch: out endpoint count high byte eoch holds the upper 2-bits of the 10-bit number of data bytes in the last received packet in the cur- rent out endpoint fifo. this number is only valid while oprdy = ?1?. rrrrrrrrreset value - - - - - - e0ch 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 usb address: 0x17
c8051f320/1 rev. 1.1 173 table 15.4. usb transceiver electrical characteristics vdd = 3.0 to 3.6v, -40c to +85c unless otherwise specified parameters symbol conditions min typ max units transmitter output high voltage v oh 2.8 v output low voltage v ol 0.8 v output crossover point v crs 1.3 2.0 v output impedance z drv driving high driving low 38 38 ? pull-up resistance r pu full speed (d+ pull-up) low speed (d- pull-up) 1.425 1.5 1.575 k ? output rise time t r low speed full speed 75 4 300 20 ns output fall time t f low speed full speed 75 4 300 20 ns receiver differential input sensitivity v di | (d+) - (d-) | 0.2 v differential input com- mon mode range v cm 0.8 2.5 v input leakage current i l pullups disabled <1.0 a note: refer to the usb specification for timing diagrams and symbol definitions.
c8051f320/1 174 rev. 1.1 notes
c8051f320/1 rev. 1.1 175 16. smbus the smbus i/o interface is a two-wire, bi-directional serial bus. the smbus is compliant with the system manage - ment bus specification, version 1.1, and compatible with the i 2 c serial bus. reads and writes to the interface by the system controller are byt e oriented with the smbus inte rface autonomously contro lling the serial transfer of the data. data can be transferred at up to 1/10th of the system clock as a master or slave (this can be faster than allowed by the smbus specification, depending on the system clock used). a method of extending the clock-low duration is avail - able to accommodate devices with diff erent speed capabilitie s on the same bus. the smbus interface may operate as a master and/or slave, and may function on a bus with multiple masters. the smbus provides control of sda (serial data), scl (serial clock) generation an d synchronization, arbitration logic, and start/stop control and generation. three sfrs are associated with the smbus: smb0cf configures the smbus; smb0cn controls the status of the smbus; and smb0dat is the data register, used for both transmitting and receiving smbus data and slave addresses. figure 16.1. smbus block diagram data path control smbus control logic c r o s s b a r scl filter n sda control scl control arbitration scl synchronization irq generation scl generation (master mode) sda control interrupt request port i/o smb0cn s t a a c k r q a r b l o s t a c k s i t x m o d e m a s t e r s t o 01 00 10 11 t0 overflow t1 overflow tmr2h overflow tmr2l overflow smb0cf e n s m b i n h b u s y e x t h o l d s m b t o e s m b f t e s m b c s 1 s m b c s 0 0 1 2 3 4 5 6 7 smb0dat sda filter n
c8051f320/1 176 rev. 1.1 16.1. supporting documents it is assumed the reader is familiar with or has access to the following supporting documents: 1. the i 2 c-bus and how to use it (including specifications), philips semiconductor. 2. the i 2 c-bus specification -- version 2.0, philips semiconductor. 3. system management bus specification -- version 1.1, sbs implementers forum. 16.2. smbus configuration figure 16.2 shows a typical smbus configurat ion. the smbus specifi cation allows any recessive voltage between 3.0 v and 5.0 v; different devices on the bus may operate at diff erent voltage levels. the bi-directional scl (serial clock) and sda (serial data) lines must be connected to a positive power supply voltage through a pull-up resistor or similar circuit. every device connected to the bus must have an open-drain or open-collector output for both the scl and sda lines, so that both are pulled high (recessive stat e) when the bus is free. th e maximum number of devices on the bus is limited only by the requirement that the rise and fall times on the bus not exceed 300 ns and 1000 ns, respectively. figure 16.2. typical smbus configuration vdd = 5v master device slave device 1 slave device 2 vdd = 3v vdd = 5v vdd = 3v sda scl
c8051f320/1 rev. 1.1 177 16.3. smbus operation two types of data transfers are possib le: data transfers from a master tran smitter to an addressed slave receiver (write), and data transfers from an addressed slave transmitter to a master receiver (read). the master device ini - tiates both types of data transfers and provides the serial clock pulses on scl. the smbus interface may operate as a master or a slave, and multiple master devices on the same bus are supported. if two or more masters attempt to ini - tiate a data transfer simultaneously, an arbitration scheme is employed with a single master always winning the arbi - tration. note that it is not necessary to specify one device as the master in a system; any device who transmits a start and a slave address becomes the mast er for the duration of that transfer. a typical smbus transaction consists of a start cond ition followed by an address byte (bits7-1: 7-bit slave address; bit0: r/w direction b it), one or more bytes of data, and a stop condition. each byte that is received (by a master or slave) must be acknowledged (a ck) with a low sda during a high scl (see figure 16.3 ). if the receiving device does not ack, the transmitting device will read a nack (not acknowledge), which is a high sda during a high scl. the direction bit (r/w) occupies the leas t-significant bit position of the address byte. the direction bit is set to logic 1 to indicate a "read" operatio n and cleared to logic 0 to indicate a "write" operation. all transactions are initiated by a master , with one or more addressed slave devi ces as the target. the master gener - ates the start condition and then transm its the slave address and direction bit. if the transaction is a write opera - tion from the master to the slave, the ma ster transmits the data a byte at a time waiting for an ac k from the slave at the end of each byte. for read operations , the slave transmits the data waiting for an ack from the master at the end of each byte. at the end of the data transfer, the mast er generates a stop condition to terminate the transaction and free the bus. figure 16.3 illustrates a typical smbus transaction. 16.3.1. arbitration a master may start a transfer only if the bus is free. th e bus is free after a stop condition or after the scl and sda lines remain high for a specified time (see section ?16.3.4. scl high (smbus free) timeout? on page 178 ). in the event that two or more devices attempt to begin a transfer at the same time, an arbitration scheme is employed to force one master to give up the bus. the master devices continue transmitting until one attempts a high while the other transmits a low. since the bus is open-drain, the bus will be pulled low. the master attempting the high will detect a low sda and lose the arbitration. the winni ng master continues its transmission without interruption; the losing master becomes a slave and receives the rest of th e transfer if addressed. this arbitration scheme is non- destructive: one device always wins, and no data is lost. figure 16.3. smbus transaction sla6 sda sla5-0 r/w d7 d6-0 scl slave address + r/w data byte start ack nack stop
c8051f320/1 178 rev. 1.1 16.3.2. clock low extension smbus provides a clock synchroni zation mechanism, similar to i 2 c, which allows devices with different speed capa - bilities to coexist on the bus. a clock-low extension is used during a transfer in order to allow slower slave devices to communicate with faster masters. the slave may temporarily hold the scl line low to extend the clock low period, effectively decreasing the serial clock frequency. 16.3.3. scl low timeout if the scl line is held low by a slave device on the bus, no further communication is possible. furthermore, the mas - ter cannot force the scl line high to co rrect the error condition. to solve this problem, the smbus protocol specifies that devices participating in a transfer must detect any clock cycle held low longer than 25 ms as a ?timeout? condi - tion. devices that have detected the timeout condition must reset the communication no later than 10 ms after detect - ing the timeout condition. when the smbtoe bit in smb0cf is set, timer 3 is used to detect scl low timeouts. timer 3 is forced to reload when scl is high, and allowed to count when scl is low. with timer 3 enabled and configured to overflow after 25 ms (and smbtoe set), the timer 3 interrupt service routine can be used to reset (disable and re-enable) the smbus in the event of an scl low timeout. 16.3.4. scl high (smbus free) timeout the smbus specification stipulates that if the scl and sda lines remain high for more that 50 s, the bus is desig - nated as free. when the smbfte bit in smb0cf is set, the bus will be cons idered free if scl and sda remain high for more than 10 smbus clock source periods. if the smbus is waitin g to generate a master start, the start will be generated following this timeout. note that a clock sour ce is required for free timeout detection, even in a slave- only implementation.
c8051f320/1 rev. 1.1 179 16.4. using the smbus the smbus can operate in both master and slave modes. the interf ace provides timing and shif ting control for serial transfers; higher level protocol is determined by user software. the smbus interface provides the following applica - tion-independent features: ? byte-wise serial data transfers ? clock signal generation on scl (master mode only) and sda data synchronization ? timeout/bus error recognition, as defi ned by the smb0cf configuration register ? start/stop timing, detection, and generation ? bus arbitration ? interrupt generation ? status information smbus interrupts are generated for each data byte or slave ad dress that is transferred. wh en transmitting, this inter - rupt is generated after the ack cycle so that software may read the received ack value; when receiving data, this interrupt is generated before the ack cycle so that software may define the outgoing ack value. see section ?16.5. smbus transfer modes? on page 187 for more details on transmission sequences. interrupts are also generated to indicate the beginning of a transfer when a mast er (start generated), or the end of a transfer when a slave (stop detected). software should read the smb0cn (smbus control register) to find the cause of the smbus interrupt. the smb0cn register is described in section ?16.4.2. smb0cn control register? on page 183 ; table 16.4 provides a quick smb0cn decoding reference. smbus configuration options include: ? timeout detection (scl low timeout and/or bus free timeout) ? sda setup and hold time extensions ? slave event enable/disable ? clock source selection these options are selected in the smb0cf register, as described in section ?16.4.1. smbus configuration regis - ter? on page 180 .
c8051f320/1 180 rev. 1.1 16.4.1. smbus configuration register the smbus configuration register (smb0cf) is used to en able the smbus master and/or slave modes, select the smbus clock source, and select the smbus timing and time out options. when the ensmb bit is set, the smbus is enabled for all master and slave events. slave events may be disabled by setti ng the inh bit. with slave events inhib - ited, the smbus interface will still m onitor the scl and sda pins; however, the interface will nack all received addresses and will not generate any slave interrupts. when th e inh bit is set, all slave events will be inhibited follow - ing the next start (interrupts will continue for the duration of the current transfer). the smbcs1-0 bits select the smbus cloc k source, which is used only when op erating as a master or when the free timeout detection is enabled. when oper ating as a master, overflows from the selected source determine the absolute minimum scl low and high times as defined in equation 16.1 . note that the selected clock source may be shared by other peripherals so long as the timer is left running at all times. for example, timer 1 overflows may generate the smbus and uart baud rates simultaneously. timer configuration is covered in section ?19. timers? on page 217 . the selected clock source should be configured to establish the minimum scl high and low times as per equation 16.1 . when the interface is operating as a master (and sc l is not driven or extended by any other devices on the bus), the typical smbus bit rate is approximated by equation 16.2 . table 16.1. smbus clock source selection smbcs1 smbcs0 smbus clock source 0 0 timer 0 overflow 0 1 timer 1 overflow 1 0 timer 2 high byte overflow 1 1 timer 2 low byte overflow equation 16.1. minimum scl high and low times t highmin t lowmin 1 f clocksourceoverflow ---------------- ------------------ ----------- - == equation 16.2. typical smbus bit rate bitrate f clocksourceoverflow 3 --------------- ----------------- ------------- - =
c8051f320/1 rev. 1.1 181 figure 16.4 shows the typical scl generation described by equation 16.2 . notice that t high is typically twice as large as t low . the actual scl output may vary due to other devices on the bus (scl may be extended low by slower slave devices, or driven low by contending master devices). the bit rate when operating as a master will never exceed the limits defined by equation equation 16.1 . setting the exthold bit extends the minimum setup a nd hold times for the sda line. the minimum sda setup time defines the absolute minimum time that sda is stable before scl transitions from low-to-high. the minimum sda hold time defines the absolute minimum time that th e current sda value remains stable after scl transitions from high-to-low. exthold should be set so that the minimum setup and hold times meet the smbus specification requirements of 250 ns and 300 ns, respectively. table 16.2 shows the minimum setup and hold times for the two exthold settings. setup and hold time extensions are typically necessary when sysclk is above 10 mhz. with the smbtoe bit set, timer 3 should be configured to overflow after 25 ms in order to detect scl low timeouts (see section ?16.3.3. scl low timeout? on page 178 ). the smbus interface will force timer 3 to reload while scl is high, and allow timer 3 to count when scl is low. the timer 3 interrupt service routine should be used to reset smbus communication by disabling and re-enabling the smbus. smbus free timeout detection can be enabled by setting the smbfte bit. when this bit is set, the bus will be con - sidered free if sda and scl remain high for more than 10 smbus clock source periods (see figure 16.4 ). when a free timeout is detected, the interface will respond as if a stop was detected (an interr upt will be generated, and sto will be set). table 16.2. minimum sda setup and hold times exthold minimum sda setup time minimum sda hold time 0 t low - 4 system clocks or 1 system clock + s/w delay ? 3 system clocks 1 11 system clocks 12 system clocks ? setup time for ack bit transmissions and the msb of all data transfers. the s/w delay occurs between the time smb0dat or ack is wr itten and when si is cleared. note that if si is cleared in the same write that defines the outgoing ack value, s/w delay is zero. scl timer source overflows scl high timeout t low t high figure 16.4. typical smbus scl generation
c8051f320/1 182 rev. 1.1 figure 16.5. smb0cf: smbus clock/configuration register bit7: ensmb: smbus enable. this bit enables/disables the smbus interface. when enabled, the interface c onstantly monitors the sda and scl pins. 0: smbus interface disabled. 1: smbus interface enabled. bit6: inh: smbus slave inhibit. when this bit is set to logic 1, the smbus does no t generate an interrupt wh en slave events occur. this effectively removes the smbus slave from the bus. master mode interrupts are not affected. 0: smbus slave mode enabled. 1: smbus slave mode inhibited. bit5: busy: smbus busy indicator. this bit is set to logic 1 by hardware when a transfer is in progress. it is cleared to logic 0 when a stop or free-timeout is sensed. bit4: exthold: smbus setup and hold time extension enable. this bit controls the sda setup and hold times according to . 0: sda extended setup and hold times disabled. 1: sda extended setup and hold times enabled. bit3: smbtoe: smbus scl timeout detection enable. this bit enables scl low timeout detection. if set to logic 1, the smbus forces timer 3 to reload while scl is high and allows timer 3 to count when scl goes low. timer 3 should be programmed to generate interrupts at 25 ms, and the timer 3 interrupt service routine should reset smbus commu- nication. bit2: smbfte: smbus free timeout detection enable. when this bit is set to logic 1, the bus will be considered free if scl and sda remain high for more than 10 smbus clock source periods. bits1-0: smbcs1-smbcs0: smbus clock source selection. these two bits select the smbus clock source, which is used to generate the smbus bit rate. the selected device should be configur ed according to equation 16.1. r/w r/w r r/w r/w r/w r/w r/w reset value ensmb inh busy exthold smbtoe smbfte smbcs1 smbcs0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc1 smbcs1 smbcs0 smbus clock source 0 0 timer 0 overflow 0 1 timer 1 overflow 1 0 timer 2 high byte overflow 1 1 timer 2 low byte overflow
c8051f320/1 rev. 1.1 183 16.4.2. smb0cn control register smb0cn is used to control the interface and to provide status information (see figure 16.6 ). the higher four bits of smb0cn (master, txmode, sta, and sto) form a status v ector that can be used to jump to service routines. master and txmode indicate the master/slave st ate and transmit/receive modes, respectively. sta and sto indicate that a start and/or stop has been detected or generated since the last smbus interrupt. sta and sto are also used to generate start and stop conditions when operating as a master. writing a ?1? to sta will cause the smbus interf ace to enter master mode and generate a start when the bus becomes free (sta is not cleared by hardware after the start is generated). wr iting a ?1? to sto while in master mode will cause the interface to generate a stop and end th e current transfer after the next ack cycle. if sto and sta are both set (while in master mode), a stop followed by a start will be generated. as a receiver, writing the ack bit define s the outgoing ack value; as a transm itter, reading the ack bit indicates the value received on the last ack cycle. ackrq is set each time a byte is received, indicating th at an outgoing ack value is needed. when ackrq is set, software shoul d write the desired outgoing value to the ack bit before clearing si. a nack will be generated if software does not write the ack bit before cl earing si. sda will reflect the defined ack value immediately following a write to the ack bit; however scl will remain low until si is cleared. if a received slave address is not acknowledged, furthe r slave events will be ignored until the next start is detected. the arblost bit indicates that the inte rface has lost an arbitration. this ma y occur anytime the interface is trans - mitting (master or slave). a lost arbitration while operatin g as a slave indicates a bus error condition. arblost is cleared by hardware each time si is cleared. the si bit (smbus interrupt flag) is se t at the beginning and end of each transfer , after each byte frame, or when an arbitration is lost; see table 16.3 for more details. important note about the si bit: the smbus interface is stalled while si is set; thus scl is held low, and the bus is stalled until software clears si. table 16.3 lists all sources for hardware changes to the smb0cn bits. refer to table 16.4 for smbus status decoding using the smb0cn register.
c8051f320/1 184 rev. 1.1 figure 16.6. smb0cn: smbus control register bit7: master: smbus master/slave indicator. this read-only bit indicates when th e smbus is operating as a master. 0: smbus operating in slave mode. 1: smbus operating in master mode. bit6: txmode: smbus transmit mode indicator. this read-only bit indicates when the smbus is operating as a transmitter. 0: smbus in receiver mode. 1: smbus in transmitter mode. bit5: sta: smbus start flag. write: 0: no start generated. 1: when operating as a master, a start condition is transmitted if the bus is free (if the bus is not free, the start is transmitte d after a stop is received or a timeout is detected). if sta is set by soft- ware as an active master, a repeated start will be generated after the next ack cycle. read: 0: no start or repeated start detected. 1: start or repeated start detected. bit4: sto: smbus stop flag. write: 0: no stop condition is transmitted. 1: setting sto to logic 1 causes a stop condition to be transmitted after th e next ack cycle. when the stop condition is generated, hardware clears st o to logic 0. if both sta and sto are set, a stop condition is transmitted followed by a start condition. read: 0: no stop condition detected. 1: stop condition detected (if in slave mode) or pending (if in master mode). bit3: ackrq: smbus acknowledge request this read-only bit is set to logic 1 when the smbu s has received a byte and needs the ack bit to be written with the correct ack response value. bit2: arblost: smbus arbitration lost indicator. this read-only bit is set to logic 1 when the smbus loses arbitration while operating as a transmitter. a lost arbitration while a slav e indicates a bus error condition. bit1: ack: smbus acknowledge flag. this bit defines the out-going ack level and record s incoming ack levels. it should be written each time a byte is received (when ackrq=1), or read after each byte is transmitted. 0: a "not acknowledge" has been received (if in tr ansmitter mode) or will be transmitted (if in receiver mode). 1: an "acknowledge" has been r eceived (if in transmitter mode) or will be transmitted (if in receiver mode). bit0: si: smbus interrupt flag. this bit is set by hardware under the conditions listed in table 16.3. si must be cleared by software. while si is set, scl is held low and the smbus is stalled. r r r/w r/w r r r/w r/w reset value master txmode sta sto ackrq arblost ack si 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: 0xc0
c8051f320/1 rev. 1.1 185 table 16.3. sources for hardware changes to smb0cn bit set by hardware when: cleared by hardware when: master ? a start is generated. ? a stop is generated. ? arbitration is lost. txmode ? start is generated. ? smb0dat is written before the start of an smbus frame. ? a start is detected. ? arbitration is lost. ? smb0dat is not written before the start of an smbus frame. sta ? a start followed by an address byte is received. ? must be cleared by software. sto ? a stop is detected while addressed as a slave. ? arbitration is lost due to a detected stop. ? a pending stop is generated. ackrq ? a byte has been received and an ack response value is needed. ? after each ack cycle. arblost ? a repeated start is detected as a master when sta is low (unwanted repeated start). ? scl is sensed low while attempting to generate a stop or repeated start condition. ? sda is sensed low while transmitting a ?1? (excluding ack bits). ? each time si is cleared. ack ? the incoming ack value is low (acknowl - edge). ? the incoming ack value is high (not acknowledge). si ? a start has been generated. ? lost arbitration. ? a byte has been transmitted and an ack/nack received. ? a byte has been received. ? a start or repeated start followed by a slave address + r/w has been received. ? a stop has been received. ? must be cleared by software.
c8051f320/1 186 rev. 1.1 16.4.3. data register the smbus data register smb0dat holds a byte of serial data to be transmitted or one th at has just been received. software may safely read or write to th e data register when the si flag is se t. software should not attempt to access the smb0dat register when the smbus is enab led and the si flag is cleared to logic 0, as the interface may be in the process of shifting a byte of data into or out of the register. data in smb0dat is always shifted out msb first. after a byte has been received, the first bit of received data is located at the msb of smb0dat. while data is being shifte d out, data on the bus is simultaneously being shifted in. smb0dat always contains the last data byte present on the bu s. in the event of lost arbi tration, the transition from master transmitter to slave receiver is made with the co rrect data or address in smb0dat. figure 16.7. smb0dat: smbus data register bits7-0: smb0dat: smbus data. the smb0dat register contains a byte of data to be transmitted on the smbus serial interface or a byte that has just been r eceived on the smbus serial interface. the cpu can read from or write to this register whenever the si serial inte rrupt flag (smb0cn.0) is set to logic 1. the serial data in the reg- ister remains stable as long as the si flag is set. wh en the si flag is not set, the system may be in the process of shifting data in/out and the cp u should not attempt to access this register. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc2
c8051f320/1 rev. 1.1 187 16.5. smbus transfer modes the smbus interface may be configured to op erate as master and/or sl ave. at any particular t ime, it will be operating in one of the following four modes: master transmitter, master receiver, slave transmitter, or slave receiver. the smbus interface enters master mode any time a start is generated, and remains in master mode until it loses an arbitration or generates a stop. an smbus interrupt is gene rated at the end of all smbu s byte frames; however, note that the interrupt is generated before the ack cycle wh en operating as a receiver, and after the ack cycle when operating as a transmitter. 16.5.1. master transmitter mode serial data is transmitted on sda wh ile the serial clock is output on scl. the smbus interface generates the start condition and transmits the first byte containing the address of the target slave and the data direction bit. in this case the data direction bit (r/w) will be logic 0 (write). the master then transmits one or more bytes of serial data. after each byte is transmitted, an acknowl edge bit is generated by the slave. th e transfer is ended when the sto bit is set and a stop is generated. note that the interface will switch to master receiver mode if smb0dat is not writ - ten following a master transmitter interrupt. figure 16.8 shows a typical master transm itter sequence. two transmit data bytes are shown, though any number of bytes may be tr ansmitted. notice that the ?d ata byte transferred? inter - rupts occur after the ack cycle in this mode. a a a s w p data byte data byte sla s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt figure 16.8. typical master transmitter sequence
c8051f320/1 188 rev. 1.1 16.5.2. master receiver mode serial data is received on sda while the serial clock is output on scl. the smbus interface generates the start condition and transmits the first byte containing the address of the target slave and the data direction bit. in this case the data direction bit (r/w) will be logic 1 (read). serial data is then recei ved from the slave on sda while the smbus outputs the serial clock. the slave transmits one or more bytes of serial data. after each byte is received, ackrq is set to ?1? and an interrupt is generated. soft ware must write the ack bit (smb0cn.1) to define the out - going acknowledge value (note: writing a ?1? to the ack bit generates an ack; writing a ?0? generates a nack). software should write a ?0? to the ack bit after the last byte is received, to transmit a nack. the interface exits master receiver mode after the sto bit is set and a stop is generated. note that the inte rface will switch to master transmitter mode if smb0dat is writ ten while an active master receiver. figure 16.9 shows a typical master receiver sequence. two received data byt es are shown, though any number of bytes may be received. notice that the ?data byte transferred? interrupts occur before the ack cycle in this mode. figure 16.9. typical master receiver sequence data byte data byte a n a s r p sla s = start p = stop a = ack n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt
c8051f320/1 rev. 1.1 189 16.5.3. slave receiver mode serial data is received on sda and the clock is received on scl. when slave events are enabled (inh = 0), the inter - face enters slave receiver mode when a start followed by a slave address and direction bit (write in this case) is received. upon entering slave receiver mode, an interr upt is generated and the ackrq bit is set. software responds to the received slave address with an ack, or ignores the receive d slave address with a nack. if the received slave address is ignored, slave in terrupts will be inhibited until the ne xt start is detected. if the received slave address is acknowledged, zero or more data bytes are received. software must write the ack bit after each received byte to ack or nack the received byte. the inte rface exits slave receiver mo de after receiving a stop. note that the interface will switch to slave transmitter mode if smb0dat is written while an active slave receiver. figure 16.10 shows a typical slave receiver sequence. two recei ved data bytes are shown, though any number of bytes may be received. notice that the ?d ata byte transferred? interrupts occur before the ack cycle in this mode. p w sla s data byte data byte a a a s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt figure 16.10. typical sl ave receiver sequence
c8051f320/1 190 rev. 1.1 16.5.4. slave transmitter mode serial data is transmitted on sda an d the clock is received on scl. when sl ave events are enabled (inh = 0), the interface enters slave receiver mode (t o receive the slave address) when a start followed by a slave address and direction bit (read in this case) is received. upon enteri ng slave transmitter mode, an interrupt is generated and the ackrq bit is set. software responds to the received sl ave address with an ack, or ignores the received slave address with a nack. if the received sl ave address is ignored, sl ave interrupts will be inhibited until a start is detected. if the received slave address is acknowledged, data should be writte n to smb0dat to be transmitted. the interface enters slave transmitter mode, and transmits one or more bytes of data. after each byte is transmitted, the master sends an acknowledge bit; if th e acknowledge bit is an ack, smb0dat should be written with the next data byte. if the acknowledge bit is a nack, smb0dat should not be written to before si is cleared (n ote: an error con - dition may be generated if smb0dat is written following a received nack wh ile in slave transmitter mode). the interface exits slave transmitter mode af ter receiving a stop. note that the in terface will switch to slave receiver mode if smb0dat is not written following a slave transmitter interrupt. figure 16.11 shows a typical slave trans - mitter sequence. two transmitted data bytes are shown, tho ugh any number of bytes may be transmitted. notice that the ?data byte transferred? interrupts occur after the ack cycle in this mode. p r sla s data byte data byte a n a s = start p = stop n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt figure 16.11. typical slave transmitter sequence
c8051f320/1 rev. 1.1 191 16.6. smbus status decoding the current smbus status can be easily decoded using the smb0cn register. in the table below, status vector refers to the four upper bits of smb0cn: master, txmode, sta, and sto. note that the shown response options are only the typical responses; application-specific procedur es are allowed as long as they conform to the smbus specification. highlighted re sponses are allowed but do not conform to the smbus specification. table 16.4. smbus status decoding mode values read current smbus state typical response options values written status vector ackrq arblost ack sta sto ack master transmitter 1110 0 0 x a master start was generated. load slave address + r/w into smb0dat. 0 0 x 1100 000 a master data or address byte was transmitted; nack received. set sta to restart transfer. 1 0 x abort transfer. 0 1 x 001 a master data or address byte was transmitted; ack received. load next data byte into smb0dat. 0 0 x end transfer with stop. 0 1 x end transfer with stop and start another transfer. 1 1 x send repeated start. 1 0 x switch to master receiver mode (clear si without writing new data to smb0dat). 0 0 x master receiver 1000 1 0 x a master data byte was received; ack requested. acknowledge received byte; read smb0dat. 0 0 1 send nack to indicate last byte, and send stop. 0 1 0 send nack to indicate last byte, and send stop followed by start. 1 1 0 send ack followed by repeated start. 1 0 1 send nack to indicate last byte, and send repeated start. 1 0 0 send ack and switch to master transmitter mode (write to smb0dat before clearing si). 0 0 1 send nack and switch to mas - ter transmitter mode (write to smb0dat before clearing si). 0 0 0
c8051f320/1 192 rev. 1.1 slave transmitter 0100 000 a slave byte was transmitted; nack received. no action required (expecting stop condition). 0 0 x 001 a slave byte was transmitted; ack received. load smb0dat with next data byte to transmit. 0 0 x 01x a slave byte was tr ansmitted; error detected. no action required (expecting master to end transfer). 0 0 x 0101 0 x x a stop was detected while an addressed slave transmitter. no action required (transfer complete). 0 0 x slave receiver 0010 10x a slave address was received; ack requested. acknowledge received address. 0 0 1 do not acknowledge received address. 0 0 0 11x lost arbitration as master; slave address received; ack requested. acknowledge received address. 0 0 1 do not acknowledge received address. 0 0 0 reschedule failed transfer; do not acknowledge received address. 1 0 0 0010 0 1 x lost arbitration while attempting a repeated start. abort failed transfer. 0 0 x reschedule failed transfer. 1 0 x 0001 11x lost arbitration while attempting a stop. no action required (transfer complete/aborted). 0 0 0 00x a stop was detected while an addressed slave receiver. no action required (transfer complete). 0 0 x 01x lost arbitration due to a detected stop. abort transfer. 0 0 x reschedule failed transfer. 1 0 x 0000 10x a slave byte was received; ack requested. acknowledge received byte; read smb0dat. 0 0 1 do not acknowledge received byte. 0 0 0 11x lost arbitration while transmitting a data byte as master. abort failed transfer. 0 0 0 reschedule failed transfer. 1 0 0 table 16.4. smbus st atus decoding mode values read current smbus state typical response options values written status ve cto r ackrq arblost ack sta sto ack
c8051f320/1 rev. 1.1 193 17. uart0 uart0 is an asynchronous, full duplex serial port offering modes 1 and 3 of the standard 8051 uart. enhanced baud rate support allows a wide range of clock sour ces to generate standard baud rates (details in section ?17.1. enhanced baud rate generation? on page 194 ). received data buffering a llows uart0 to start reception of a second incoming data byte before software has finished reading the previous data byte. uart0 has two associated sfrs: serial control register 0 (scon0) and serial data buffer 0 (sbuf0). the single sbuf0 location provides access to both transmit and receive registers. writes to sbuf0 always access the trans - mit register. reads of sbuf0 always access the buffered r eceive register; it is not po ssible to read data from the transmit register. with uart0 interrupts enabled, an interrupt is generated each time a transmit is completed (ti0 is set in scon0), or a data byte has been received (ri0 is set in scon0). th e uart0 interrupt flags are not cleared by hardware when the cpu vectors to the interrupt service routine. they mu st be cleared manually by software, allowing software to determine the cause of the uart0 interrupt (transmit complete or receive complete). figure 17.1. uart0 block diagram uart baud rate generator ri scon ri ti rb8 tb8 ren mce smode tx control tx clock send sbuf (tx shift) start data write to sbuf crossbar tx shift zero detector tx irq set q d clr stop bit tb8 sfr bus serial port interrupt ti port i/o rx control start rx clock load sbuf shift 0x1ff rb8 rx irq input shift register (9 bits) load sbuf read sbuf sfr bus crossbar rx sbuf (rx latch)
c8051f320/1 194 rev. 1.1 17.1. enhanced baud rate generation the uart0 baud rate is generated by timer 1 in 8-bit auto-reload mode. the tx clock is generated by tl1; the rx clock is generated by a copy of tl1 (shown as rx timer in figure 17.2 ), which is not user-accessible. both tx and rx timer overflows are divided by two to generate the tx and rx baud rates. the rx timer runs when timer 1 is enabled, and uses the same reload value (th1). however, an rx timer reload is forced when a start condition is detected on the rx pin. this allows a receive to begin any time a start is detected, independent of the tx timer state. timer 1 should be configured for mode 2, 8-bit auto-reload (see section ?19.1.3. mode 2: 8-bit counter/timer with auto-reload? on page 219 ). the timer 1 reload value should be set so that overflows will occur at two times the desired uart baud rate frequency. note that timer 1 may be clocked by one of six sources: sysclk, sysclk / 4, sysclk / 12, sysclk / 48, the external oscillator clock / 8, or an external input t1. for any given timer 1 clock source, the uart0 baud rate is determined by equation 17.1 . where t1 clk is the frequency of the clock supplied to timer 1, and t1h is the high byte of timer 1 (reload value). timer 1 clock frequency is selected as described in section ?19. timers? on page 217 . a quick reference for typical baud rates and system clock frequencies is given in table 17.1 through table 17.6 . note that the internal oscillator may still generate the system clock when th e external oscillator is driving timer 1. figure 17.2. uart0 baud rate logic rx timer start detected overflow overflow th1 tl1 tx clock 2 rx clock 2 timer 1 uart equation 17.1. uart0 baud rate uartbaudrate t 1 clk 256 t 1 h ? () ----------------- ------------- - 1 2 -- - =
c8051f320/1 rev. 1.1 195 17.2. operational modes uart0 provides standard asynchronous, full duplex communi cation. the uart mode (8-bit or 9-bit) is selected by the s0mode bit (scon0.7). typical uart connection options are shown below. 17.2.1. 8-bit uart 8-bit uart mode uses a total of 10 bits per data byte: one start bit, eight data bits (lsb first), and one stop bit. data are transmitted lsb first from the tx0 pi n and received at the rx0 pi n. on receive, the eight da ta bits are stored in sbuf0 and the stop bit goes into rb80 (scon0.2). data transmission begins when software writes a data byte to the sbuf0 re gister. the ti0 tran smit interrupt flag (scon0.1) is set at the end of the tr ansmission (the beginning of the stop -bit time). data reception can begin any time after the ren0 receive enable bit (scon0.4) is set to logic 1. after the stop bit is received, the data byte will be loaded into the sbuf0 receive register if th e following conditions are met: ri0 must be logic 0, and if mce0 is logic 1, the stop bit must be logic 1. in the event of a receive data overrun, the first received 8 bits are latched into the sbuf0 receive register and the foll owing overrun data bits are lost. if these conditions are met, the eight bits of data is stored in sbuf0, the st op bit is stored in rb80 and the ri0 flag is set. if these conditions are not met, sbuf0 and rb80 will not be loaded and the ri0 flag will not be set. an interrupt will occur if enab led when either ti0 or ri0 is set. figure 17.3. uart interconnect diagram or rs-232 c8051fxxx rs-232 level xltr tx rx c8051fxxx rx tx mcu rx tx figure 17.4. 8-bit uart timing diagram d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space
c8051f320/1 196 rev. 1.1 17.2.2. 9-bit uart 9-bit uart mode uses a total of eleven bits per data byte: a start bit, 8 data bits (lsb first), a programmable ninth data bit, and a stop bit. the state of the ninth transmit data bit is determined by the value in tb80 (scon0.3), which is assigned by user software. it can be assigned the value of the parity flag (bit p in register psw) for error detection, or used in multiprocessor communications. on receive, the ninth data bit goes into rb80 (scon0.2) and the stop bit is ignored. data transmission begins when an instruction writes a da ta byte to the sbuf0 register. the ti0 transmit interrupt flag (scon0.1) is set at the end of the transmission (the beginning of the stop-bit time). data reception can begin any time after the ren0 receive enable b it (scon0.4) is set to ?1?. after the stop bit is received, the data byte will be loaded into the sbuf0 receive re gister if the following conditions are met: (1) ri0 must be logic 0, and (2) if mce0 is logic 1, the 9th bit must be logic 1 (when mce0 is logic 0, the state of the ninth data bit is unimportant). if these conditions are met, the eight bits of data are stored in sbuf0, the ninth bit is stored in rb80, and the ri0 flag is set to ?1?. if the above conditions are not met, sbuf0 and rb80 will not be loaded and the ri0 flag will not be set to ?1?. a uart0 interrupt will occur if enable d when either ti0 or ri0 is set to ?1?. figure 17.5. 9-bit uart timing diagram d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space d8
c8051f320/1 rev. 1.1 197 17.3. multiprocessor communications 9-bit uart mode supports multiprocessor communication be tween a master processor and one or more slave pro - cessors by special use of the ninth data b it. when a master processor wants to tr ansmit to one or more slaves, it first sends an address byte to select the target (s). an address byte differs from a data byte in that its ninth bit is logic 1; in a data byte, the ninth bit is always set to logic 0. setting the mce0 bit (sc on0.5) of a slave proce ssor configures its uart such that when a stop bit is received, the uart will generate an interrupt only if the ninth bit is logic 1 (rb80 = 1) signifying an address byte has been received. in the uart interrupt handler, software will compare the received a ddress with the slave's own assigned 8- bit address. if the addresses match, th e slave will clear its mce0 bit to enable interrupts on the reception of the fol - lowing data byte(s). slaves that were n't addressed leave their mce0 bits set and do not generate interrupts on the reception of the following data bytes, thereby ignoring the data. once the enti re message is received, the addressed slave resets its mce0 bit to ignore all transm issions until it receives the next address byte. multiple addresses can be assigned to a single slave and/ or a single address can be assigned to multiple slaves, thereby enabling "broadcast" transmissi ons to more than one slav e simultaneously. the mast er processor can be con - figured to receive all transmissions or a protocol can be implemented such that the master/slave role is temporarily reversed to enable half-duplex transmission between the original master and slave(s). figure 17.6. uart multi-processo r mode interconnect diagram master device slave device tx rx rx tx slave device rx tx slave device rx tx v+
c8051f320/1 198 rev. 1.1 figure 17.7. scon0: serial port 0 control register bit7: s0mode: serial port 0 operation mode. this bit selects the uart0 operation mode. 0: 8-bit uart with variable baud rate. 1: 9-bit uart with variable baud rate. bit6: unused. read = 1b. write = don?t care. bit5: mce0: multiprocessor communication enable. the function of this bit is dependent on the serial port 0 operation mode. s0mode = 0: checks for valid stop bit. 0: logic level of stop bit is ignored. 1: ri0 will only be activated if stop bit is logic level 1. s0mode = 1: multiprocessor communications enable. 0: logic level of ninth bit is ignored. 1: ri0 is set and an interrupt is generated only when the ninth bit is logic 1. bit4: ren0: receive enable. this bit enables/disables the uart receiver. 0: uart0 reception disabled. 1: uart0 reception enabled. bit3: tb80: ninth transmission bit. the logic level of this bit will be assigned to the ninth transmission bit in 9-bit uart mode. it is not used in 8-bit uart mode. set or cleared by software as required. bit2: rb80: ninth receive bit. rb80 is assigned the value of the stop bit in mode 0; it is assigned the value of the 9th data bit in mode 1. bit1: ti0: transmit interrupt flag. set by hardware when a byte of data has been transmitted by uart0 (after the 8th bit in 8-bit uart mode, or at the beginning of the stop bit in 9-bit uart mode). when the uart0 interrupt is enabled, setting this bit causes the cpu to vector to the uart0 interrupt service routine. this bit must be cleared manually by software. bit0: ri0: receive interrupt flag. set to ?1? by hardware when a byte of data ha s been received by uart0 (set at the stop bit sam- pling time). when the uart0 interrupt is enabled, setting this bit to ?1? causes the cpu to vector to the uart0 interrupt service routine. this bit must be cleared manually by software. r/w r r/w r/w r/w r/w r/w r/w reset value s0mode - mce0 ren0 tb80 rb80 ti0 ri0 01000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: 0x98
c8051f320/1 rev. 1.1 199 figure 17.8. sbuf0: serial (uart0 ) port data buffer register bits7-0: sbuf0[7:0]: serial data buffer bits 7-0 (msb-lsb) this sfr accesses two registers; a transmit shift re gister and a receive latch register. when data is written to sbuf0, it goes to the transmit shift register and is held for serial transmission. writing a byte to sbuf0 initiates the transmi ssion. a read of sbuf0 returns th e contents of the receive latch. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x99
c8051f320/1 200 rev. 1.1 table 17.1. timer settings for standard baud ra tes using the int ernal oscillator frequency: 24.5 mhz target baud rate (bps) baud rate % error oscillator divide factor timer clock source sca1-sca0 (pre-scale select) ? t1m ? timer 1 reload value (hex) sysclk from internal osc. 230400 -0.32% 106 sysclk xx 1 0xcb 115200 -0.32% 212 sysclk xx 1 0x96 57600 0.15% 426 sysclk xx 1 0x2b 28800 -0.32% 848 sysclk / 4 01 0 0x96 14400 0.15% 1704 sysclk / 12 00 0 0xb9 9600 -0.32% 2544 sysclk / 12 00 0 0x96 2400 -0.32% 10176 sysclk / 48 10 0 0x96 1200 0.15% 20448 sysclk / 48 10 0 0x2b x = don?t care ? sca1-sca0 and t1m bit definitions can be found in section 19.1 . tab le 17.2. timer settings for standard baud ra tes using an external oscillator frequency: 25.0 mhz target baud rate (bps) baud rate % error oscillator divide factor timer clock source sca1-sca0 (pre-scale select) ? t1m ? timer 1 reload value (hex) sysclk from external osc. 230400 -0.47% 108 sysclk xx 1 0xca 115200 0.45% 218 sysclk xx 1 0x93 57600 -0.01% 434 sysclk xx 1 0x27 28800 0.45% 872 sysclk / 4 01 0 0x93 14400 -0.01% 1736 sysclk / 4 01 0 0x27 9600 0.15% 2608 extclk / 8 11 0 0x5d 2400 0.45% 10464 sysclk / 48 10 0 0x93 1200 -0.01% 20832 sysclk / 48 10 0 0x27 sysclk from internal osc. 57600 -0.47% 432 extclk / 8 11 0 0xe5 28800 -0.47% 864 extclk / 8 11 0 0xca 14400 0.45% 1744 extclk / 8 11 0 0x93 9600 0.15% 2608 extclk / 8 11 0 0x5d x = don?t care ? sca1-sca0 and t1m bit definitions can be found in section 19.1 .
c8051f320/1 rev. 1.1 201 tab le 17.3. timer settings for standard baud ra tes using an external oscillator frequency: 22.1184 mhz target baud rate (bps) baud rate % error oscillator divide factor timer clock source sca1-sca0 (pre-scale select) ? t1m ? timer 1 reload value (hex) sysclk from external osc. 230400 0.00% 96 sysclk xx 1 0xd0 115200 0.00% 192 sysclk xx 1 0xa0 57600 0.00% 384 sysclk xx 1 0x40 28800 0.00% 768 sysclk / 12 00 0 0xe0 14400 0.00% 1536 sysclk / 12 00 0 0xc0 9600 0.00% 2304 sysclk / 12 00 0 0xa0 2400 0.00% 9216 sysclk / 48 10 0 0xa0 1200 0.00% 18432 sysclk / 48 10 0 0x40 sysclk from internal osc. 230400 0.00% 96 extclk / 8 11 0 0xfa 115200 0.00% 192 extclk / 8 11 0 0xf4 57600 0.00% 384 extclk / 8 11 0 0xe8 28800 0.00% 768 extclk / 8 11 0 0xd0 14400 0.00% 1536 extclk / 8 11 0 0xa0 9600 0.00% 2304 extclk / 8 11 0 0x70 x = don?t care ? sca1-sca0 and t1m bit definitions can be found in section 19.1 . tab le 17.4. timer settings for standard baud ra tes using an external oscillator frequency: 18.432 mhz target baud rate (bps) baud rate % error oscillator divide factor timer clock source sca1-sca0 (pre-scale select) ? t1m ? timer 1 reload value (hex) sysclk from external osc. 230400 0.00% 80 sysclk xx 1 0xd8 115200 0.00% 160 sysclk xx 1 0xb0 57600 0.00% 320 sysclk xx 1 0x60 28800 0.00% 640 sysclk / 4 01 0 0xb0 14400 0.00% 1280 sysclk / 4 01 0 0x60 9600 0.00% 1920 sysclk / 12 00 0 0xb0 2400 0.00% 7680 sysclk / 48 10 0 0xb0 1200 0.00% 15360 sysclk / 48 10 0 0x60 sysclk from internal osc. 230400 0.00% 80 extclk / 8 11 0 0xfb 115200 0.00% 160 extclk / 8 11 0 0xf6 57600 0.00% 320 extclk / 8 11 0 0xec 28800 0.00% 640 extclk / 8 11 0 0xd8 14400 0.00% 1280 extclk / 8 11 0 0xb0 9600 0.00% 1920 extclk / 8 11 0 0x88 x = don?t care ? sca1-sca0 and t1m bit definitions can be found in section 19.1 .
c8051f320/1 202 rev. 1.1 tab le 17.5. timer settings for standard baud ra tes using an external oscillator frequency: 11.0592 mhz target baud rate (bps) baud rate % error oscillator divide factor timer clock source sca1-sca0 (pre-scale select) ? t1m ? timer 1 reload value (hex) sysclk from external osc. 230400 0.00% 48 sysclk xx 1 0xe8 115200 0.00% 96 sysclk xx 1 0xd0 57600 0.00% 192 sysclk xx 1 0xa0 28800 0.00% 384 sysclk xx 1 0x40 14400 0.00% 768 sysclk / 12 00 0 0xe0 9600 0.00% 1152 sysclk / 12 00 0 0xd0 2400 0.00% 4608 sysclk / 12 00 0 0x40 1200 0.00% 9216 sysclk / 48 10 0 0xa0 sysclk from internal osc. 230400 0.00% 48 extclk / 8 11 0 0xfd 115200 0.00% 96 extclk / 8 11 0 0xfa 57600 0.00% 192 extclk / 8 11 0 0xf4 28800 0.00% 384 extclk / 8 11 0 0xe8 14400 0.00% 768 extclk / 8 11 0 0xd0 9600 0.00% 1152 extclk / 8 11 0 0xb8 x = don?t care ? sca1-sca0 and t1m bit definitions can be found in section 19.1 . tab le 17.6. timer settings for standard baud ra tes using an external oscillator frequency: 3.6864 mhz target baud rate (bps) baud rate% error oscillator divide factor timer clock source sca1-sca0 (pre-scale select) ? t1m ? timer 1 reload value (hex) sysclk from external osc. 230400 0.00% 16 sysclk xx 1 0xf8 115200 0.00% 32 sysclk xx 1 0xf0 57600 0.00% 64 sysclk xx 1 0xe0 28800 0.00% 128 sysclk xx 1 0xc0 14400 0.00% 256 sysclk xx 1 0x80 9600 0.00% 384 sysclk xx 1 0x40 2400 0.00% 1536 sysclk / 12 00 0 0xc0 1200 0.00% 3072 sysclk / 12 00 0 0x80 sysclk from internal osc. 230400 0.00% 16 extclk / 8 11 0 0xff 115200 0.00% 32 extclk / 8 11 0 0xfe 57600 0.00% 64 extclk / 8 11 0 0xfc 28800 0.00% 128 extclk / 8 11 0 0xf8 14400 0.00% 256 extclk / 8 11 0 0xf0 9600 0.00% 384 extclk / 8 11 0 0xe8 x = don?t care ? sca1-sca0 and t1m bit definitions can be found in section 19.1 .
c8051f320/1 rev. 1.1 203 18. enhanced serial peri pheral interface (spi0) the enhanced serial peripheral interf ace (spi0) provides access to a flexible, full-duplex synchronous serial bus. spi0 can operate as a master or slave device in both 3-wire or 4-wire modes, and supports multiple masters and slaves on a single spi bus. the slave- select (nss) signal can be configured as an input to select spi0 in slave mode, or to disable master mode operation in a mu lti-master environment, avoiding contention on the spi bus when more than one master attempts simultaneous data transfers. nss can also be configured as a chip-sel ect output in master mode, or disabled for 3-wire operation. additional general purpose port i/o pins can be used to select multiple slave devices in master mode. figure 18.1. spi block diagram sfr bus data path control sfr bus write spi0dat receive data buffer spi0dat 0 1 2 3 4 5 6 7 shift register spi control logic spi0ckr scr7 scr6 scr5 scr4 scr3 scr2 scr1 scr0 spi0cfg spi0cn pin interface control pin control logic c r o s s b a r port i/o read spi0dat spi irq tx data rx data sck mosi miso nss transmit data buffer clock divide logic sysclk ckpha ckpol slvsel nssmd1 nssmd0 spibsy msten nssin srmt rxbmt spif wcol modf rxovrn txbmt spien
c8051f320/1 204 rev. 1.1 18.1. signal descriptions the four signals used by spi0 (mosi, miso, sck, nss) are described below. 18.1.1. master out, slave in (mosi) the master-out, slave-in (mosi) signal is an output from a master device and an input to slave devices. it is used to serially transfer data from the master to the slave. this signal is an output when spi0 is operating as a master and an input when spi0 is operating as a slave. data is transferred most-significant bi t first. when configured as a master, mosi is driven by the msb of the shift register in both 3- and 4-wire mode. 18.1.2. master in, slave out (miso) the master-in, slave-out (miso) signal is an output from a sl ave device and an input to th e master device. it is used to serially transfer data from the slave to the master. this signal is an input when spi0 is operating as a master and an output when spi0 is operating as a slave. data is transferred most-significant bi t first. the miso pin is placed in a high-impedance state when the spi module is disabled and when the spi operates in 4-wire mode as a slave that is not selected. when acting as a slave in 3-wire mode, mi so is always driven by the msb of the shift register. 18.1.3. serial clock (sck) the serial clock (sck) signal is an output from the master de vice and an input to slave devices. it is used to synchro - nize the transfer of data between the master and slave on the mosi and miso lines. spi0 generates this signal when operating as a master. the sck signal is ignored by a spi slav e when the slave is not sel ected (nss = 1) in 4-wire slave mode. 18.1.4. slave select (nss) the function of the slave-sel ect (nss) signal is dependent on the setting of the nssmd1 and nssmd0 bits in the spi0cn register. there are th ree possible modes that can be selected with these bits: 1. nssmd[1:0] = 00: 3-wire master or 3-wire slav e mode: spi0 operates in 3-wire mode, and nss is disabled. when operating as a slave de vice, spi0 is always selected in 3- wire mode. since no select signal is present, spi0 must be the only slave on the bus in 3-wire mode. this is intended for point-to-point commu - nication between a master and one slave. 2. nssmd[1:0] = 01: 4-wire slave or multi-master mode: spi0 operates in 4-wire mode, and nss is enabled as an input. when operating as a slave, nss se lects the spi0 device. when operating as a master, a 1-to-0 transition of the nss signal disables the master function of spi0 so that multiple master devices can be used on the same spi bus. 3. nssmd[1:0] = 1x: 4-wire master mode: spi0 operat es in 4-wire mode, and nss is enabled as an out - put. the setting of nssmd0 determines what logic leve l the nss pin will output. this configuration should only be used when operating spi0 as a master device. see figure 18.2 , figure 18.3 , and figure 18.4 for typical connection diagrams of the various operational modes. note that the setting of nssmd bits affects the pinout of the device. when in 3-wire master or 3-wire slave mode, the nss pin will not be mapped by the crossbar. in all other modes, the nss signal will be mapped to a pin on the device. see section ? 14. port input/output ? on page 127 for general purpose port i/o and crossbar information.
c8051f320/1 rev. 1.1 205 18.2. spi0 master mode operation a spi master device initiates all data tr ansfers on a spi bus. spi0 is placed in master mode by setting the master enable flag (msten, spi0cn.6). writing a byte of data to the spi0 data register (spi 0dat) when in master mode writes to the transmit buffer. if the spi shift register is empty, the byte in the transmit buffer is moved to the shift reg - ister, and a data transfer begins. the sp i0 master immediately shifts out the data serially on the mosi line while pro - viding the serial clock on sck. the spif (spi0cn.7) flag is set to logic 1 at th e end of the transfer. if interrupts are enabled, an interrupt request is generate d when the spif flag is set. while the spi0 master transfers data to a slave on the mosi line, the addressed spi slave device simultaneously transfers the contents of it s shift register to the spi master on the miso line in a full-duplex operation. therefor e, the spif flag serves as both a transmit-complete and receive-data-ready flag. the data byte recei ved from the slave is tran sferred msb-first into the master's shift register. when a byte is fully shifted in to the register, it is moved to the receive buf fer where it can be read by the processor by reading spi0dat. when configured as a master, spi0 can operate in one of three different mode s: multi-master mode, 3-wire single- master mode, and 4-wire single-master mode. the default, multi-master mode is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0cn.2) = 1. in this mode, nss is an in put to the device, and is used to disable the master spi0 when another master is accessing the bu s. when nss is pulled low in this mode, msten (spi 0cn.6) and spien (spi0cn.0) are set to 0 to disable th e spi master device, and a mode fault is generated (modf, spi0cn.5 = 1). mode fault will generate an interrupt if enabled. spi0 mu st be manually re-enabled in software under these circum - stances. in multi-master systems, devices will typically default to being slave devices while they are not acting as the system master device. in multi-master mode, slave devices can be addressed in dividually (if needed) using general- purpose i/o pins. figure 18.2 shows a connection diagram between two ma ster devices in multiple-master mode. 3-wire single-master mode is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0cn.2) = 0. in this mode, nss is not used, and is not mapped to an external port pi n through the crossbar. any slave devices that must be addressed in this mode should be se lected using general-purpose i/o pins. figure 18.3 shows a connection diagram between a master device in 3-wire master mode and a slave device. 4-wire single-master mode is active when nssmd1 (spi0cn.3) = 1. in this mode, nss is configured as an output pin, and can be used as a slave-select signal for a single spi device. in this mode, the output value of nss is con - trolled (in software) with the bit nssmd0 (spi0cn.2). a dditional slave devices can be addressed using general-pur - pose i/o pins. figure 18.4 shows a connection diagram for a master de vice in 4-wire master mode and two slave devices.
c8051f320/1 206 rev. 1.1 master device 2 master device 1 mosi miso sck miso mosi sck nss gpio nss gpio figure 18.2. multiple-maste r mode connection diagram figure 18.3. 3-wire single master and 3-wire single slave mode connection diagram slave device master device mosi miso sck miso mosi sck slave device master device mosi miso sck miso mosi sck nss nss gpio slave device mosi miso sck nss figure 18.4. 4-wire single master mode a nd 4-wire slave mode connection diagram
c8051f320/1 rev. 1.1 207 18.3. spi0 slave mode operation when spi0 is enabled and not c onfigured as a master, it will operate as a spi slave. as a slave, bytes are shifted in through the mosi pin and out through the miso pin by a master device controlling the sck signal. a bit counter in the spi0 logic counts sck edges. when 8 bits have been shifted through the shift register, the spif flag is set to logic 1, and the byte is copied in to the receive buffer. data is read from th e receive buffer by reading spi0dat. a slave device cannot initiate tr ansfers. data to be transferred to the master device is pre-loaded into the shift register by writ - ing to spi0dat. writes to spi0dat are double-buffered, and ar e placed in the transmit buffer first. if the shift regis - ter is empty, the contents of the transmit buffer will immedi ately be transferred into the shift register. when the shift register already contains data, the spi w ill load the shift register with the transmit buffer?s contents after the last sck edge of the next (or current) spi transfer. when configured as a slave, spi0 can be configured for 4-wire or 3-wire operation. the default, 4-wire slave mode, is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0cn. 2) = 1. in 4-wire mode, the nss signal is routed to a port pin and configured as a digital input. spi0 is enable d when nss is logic 0, and di sabled when nss is logic 1. the bit counter is reset on a falling edge of nss. note that the nss signal must be driven low at least 2 system clocks before the first active edge of sck for each byte transfer. figure 18.4 shows a connection diagram between two slave devices in 4-wire slave mode and a master device. 3-wire slave mode is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0cn.2) = 0. nss is not used in this mode, and is not mapped to an external port pin through th e crossbar. since there is no way of uniquely addressing the device in 3-wire slave mode, spi0 must be the only slave device present on the bus. it is important to note that in 3-wire slave mode there is no external means of resetting the bit counter that determines when a full byte has been received. the bit counter can only be reset by di sabling and re-enabling spi 0 with the spien bit. figure 18.3 shows a connection diagram between a slave device in 3-wire slave mode and a master device. 18.4. spi0 interrupt sources when spi0 interrupts are enabled, the fo llowing four flags will generate an interrupt when they are set to logic 1: note that all of the following bits must be cleared by software. 1. the spi interrupt flag, spi f (spi0cn.7) is set to logic 1 at the end of each byte transfer. this flag can occur in all spi0 modes. 2. the write collision flag, wcol (spi0cn.6) is set to logic 1 if a write to spi0dat is attempted when the transmit buffer has not been emptied to the spi shift register. when this occurs, the write to spi0dat will be ignored, and the transmit buffer will not be written.this flag can occur in all spi0 modes. 3. the mode fault flag modf (spi0cn.5) is set to l ogic 1 when spi0 is config ured as a master, and for multi-master mode and the nss pin is pulled low. when a mode fault occurs, the msten and spien bits in spi0cn are set to logic 0 to disable spi0 and allow another master device to access the bus. 4. the receive overrun flag rxovrn (spi0cn.4) is set to logic 1 when configured as a slave, and a transfer is completed and the receive buffer still holds an unread byte from a previous transfer. the new byte is not transferred to the receive buff er, allowing the previously received da ta byte to be read. the data byte which caused the overrun is lost.
c8051f320/1 208 rev. 1.1 18.5. serial clock timing four combinations of serial clock phase and polarity can be selected using the clock control bits in the spi0 configu - ration register (spi0cfg). the ckpha bit (spi0cfg.5) selects one of two clock phases (edge used to latch the data). the ckpol bit (spi0cfg.4) sel ects between an active-high or active- low clock. both master and slave devices must be configured to use the same clock phase an d polarity. spi0 should be disabled (by clearing the spien bit, spi0cn.0) when chan ging the clock phase or polarity. the clock a nd data line relationships for master mode are shown in figure 18.5 . for slave mode, the clock and data relationships are shown in figure 18.6 and figure 18.7 . note that ckpha must be set to ?0? on both the master and slave spi when communi cating between two of the fol - lowing devices: c8051f04x, c8051f06x, c8051 f12x, c8051f31x, c8051f32x, and c8051f33x the spi0 clock rate regist er (spi0ckr) as shown in figure 18.10 controls the master mode serial clock frequency. this register is ignored when operati ng in slave mode. when the spi is conf igured as a master, the maximum data transfer rate (bits/sec) is one-half th e system clock frequency or 12.5 mhz, whichever is slower. when the spi is con - figured as a slave, the maximum data tr ansfer rate (bits/sec) for full-duplex operation is 1/10 the system clock fre - quency, provided that the master issues sck, nss (in 4-wi re slave mode), and the serial input data synchronously with the slave?s system clock. if the ma ster issues sck, nss, and the serial input data asynchronously, the maximum data transfer rate (bits/sec) must be less than 1/10 the sy stem clock frequency. in the special case where the master only wants to transmit data to the slav e and does not need to receive data fr om the slave (i.e. half-duplex operation), the spi slave can receive data at a maximum data transfer ra te (bits/sec) of 1/4 the system clock frequency. this is provided that the master issues sck, nss, and the serial input data synchronously with the slave?s system clock. sck (ckpol=0, ckpha=0) sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=0) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso/mosi nss (must remain high in multi-master mode) figure 18.5. master mode data/clock timing
c8051f320/1 rev. 1.1 209 msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi sck (ckpol=0, ckpha=0) sck (ckpol=1, ckpha=0) figure 18.6. slave mode data/clock timing (ckpha = 0) sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi figure 18.7. slave mode data/clock timing (ckpha = 1)
c8051f320/1 210 rev. 1.1 18.6. spi special function registers spi0 is accessed and controlled through four special functi on registers in the system co ntroller: spi0cn control reg - ister, spi0dat data register, spi0cfg configuration regi ster, and spi0ckr clock rate register. the four special function registers related to the operation of th e spi0 bus are described in the following figures. figure 18.8. spi0cfg: spi0 configuration register bit 7: spibsy: spi busy (read only). this bit is set to logic 1 when a spi tran sfer is in progress (master or slave mode). bit 6: msten: master mode enable. 0: disable master mode. operate in slave mode. 1: enable master mode . operate as a master. bit 5: ckpha: spi0 clock phase. this bit controls the spi0 clock phase. 0: data centered on first edge of sck period. ? 1: data centered on second edge of sck period. ? bit 4: ckpol: spi0 clock polarity. this bit controls the spi0 clock polarity. 0: sck line low in idle state. 1: sck line high in idle state. bit 3: slvsel: slave selected flag (read only). this bit is set to logic 1 whenever the nss pin is low indicating spi0 is the selected slave. it is cleared to logic 0 when nss is high (slave not sel ected). this bit does not indicate the instantaneous value at the nss pin, but rather a de-glitched version of the pin input. bit 2: nssin: nss instantaneous pin input (read only). this bit mimics the instantaneous value that is presen t on the nss port pin at th e time that the register is read. this input is not de-glitched. bit 1: srmt: shift register empty (valid in slave mode, read only). this bit will be set to logic 1 when all data has been transferred in/out of the shift register, and there is no new information available to read from the transmit buffer or write to the receive buffer. it returns to logic 0 when a data byte is transf erred to the shift regist er from the transmit bu ffer or by a transition on sck. note: srmt = 1 when in master mode. bit 0: rxbmt: receive buffer empty (valid in slave mode, read only). this bit will be set to logic 1 when the receive buff er has been read and cont ains no new information. if there is new information available in the receive buffer that has not been read, this bit will return to logic 0. note: rxbmt = 1 when in master mode. ? in slave mode, data on mosi is sample d in the center of each data bit. in master mode, data on miso is sampled one sysclk before the end of each data bit, to provide maximu m settling time for the sl ave device. see table 18.1 for timing parameters. r r/w r/w r/w r r r r reset value spibsy msten ckpha ckpol slvsel nssin srmt rxbmt 00000111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xa1
c8051f320/1 rev. 1.1 211 figure 18.9. spi0cn: spi0 control register bit 7: spif: spi0 interrupt flag. this bit is set to logic 1 by hardware at the end of a data transfer. if interrupts are enabled, setting this bit causes the cpu to vector to the spi0 interrupt se rvice routine. this bit is not automatically cleared by hardware. it must be cleared by software. bit 6: wcol: write collision flag. this bit is set to logic 1 by hardware (and generate s a spi0 interrupt) to indi cate a write to the spi0 data register was attempted while a data transfer was in progress. it must be cleared by software. bit 5: modf: mode fault flag. this bit is set to logic 1 by hardware (and generates a spi0 interrupt) when a master mode collision is detected (nss is low, msten = 1, and nssmd[1:0] = 01). this bit is not automatically cleared by hardware. it must be cleared by software. bit 4: rxovrn: receive overr un flag (slave mode only). this bit is set to logic 1 by hardware (and genera tes a spi0 interrupt) when the receive buffer still holds unread data from a previous tr ansfer and the last bit of the curr ent transfer is shifted into the spi0 shift register. this bit is not automatically cl eared by hardware. it must be cleared by software. bits 3-2: nssmd1-nssmd0: slave select mode. selects between the following nss operation modes: (see section ?18.2. spi0 master mode operation? on page 205 and section ?18.3. spi0 slave mode operation? on page 207 ). 00: 3-wire slave or 3-wire master mode. nss signal is not routed to a port pin. 01: 4-wire slave or multi-maste r mode (default). nss is al ways an input to the device. 1x: 4-wire single-master mode. nss signal is mapped as an output from the device and will assume the value of nssmd0. bit 1: txbmt: transmit buffer empty. this bit will be set to logic 0 when new data has been written to the transmit buffer. when data in the transmit buffer is transferred to the spi shift register, this bit will be set to logic 1, indicating that it is safe to write a new byte to the transmit buffer. bit 0: spien: spi0 enable. this bit enables/disables the spi. 0: spi disabled. 1: spi enabled. r/w r/w r/w r/w r/w r/w r r/w reset value spif wcol modf rxovrn nssmd1 nssmd0 txbmt spien 00000110 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: 0xf8
c8051f320/1 212 rev. 1.1 figure 18.10. spi0ckr: sp i0 clock rate register bits 7-0: scr7-scr0: spi0 clock rate. these bits determine the frequency of the sck output when the spi0 module is configured for master mode operation. the sck clock frequency is a divided version of the system clock, and is given in the following equation, where sysclk is the system clock frequency and spi0ckr is the 8-bit value held in the spi0ckr register. for 0 <= spi0ckr <= 255 example: if sysclk = 2 mhz and spi0ckr = 0x04, r/w r/w r/w r/w r/w r/w r/w r/w reset value scr7 scr6 scr5 scr4 scr3 scr2 scr1 scr0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xa2 f sck 2000000 241 + () --------------- ----------- = f sck 200 khz = f sck sysclk 2 spi 0 ckr 1 + () --------------- ------------------ --------------- - =
c8051f320/1 rev. 1.1 213 figure 18.11. spi0dat: spi0 data register bits 7-0: spi0dat: spi0 transmit and receive data. the spi0dat register is used to transmit and recei ve spi0 data. wr iting data to sp i0dat places the data into the transmit buffer and initiates a transf er when in master mode. a read of spi0dat returns the contents of the receive buffer. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xa3
c8051f320/1 214 rev. 1.1 sck* t mckh t mckl mosi t mis miso * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mih figure 18.12. spi master timing (ckpha = 0) sck* t mckh t mckl miso t mih mosi * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mis figure 18.13. spi master timing (ckpha = 1)
c8051f320/1 rev. 1.1 215 sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t sez t sdz figure 18.14. spi slave timing (ckpha = 0) sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t slh t sez t sdz figure 18.15. spi slave timing (ckpha = 1)
c8051f320/1 216 rev. 1.1 tab le 18.1. spi slave timing parameters parameter description min max units master mode timing ? (see figure 18.12 and figure 18.13 ) t mckh sck high time 1*t sysclk ns t mckl sck low time 1*t sysclk ns t mis miso valid to sck shift edge 1*t sysclk + 20 ns t mih sck shift edge to miso change 0 ns slave mode timing ? (see figure 18.14 and figure 18.15 ) t se nss falling to first sck edge 2*t sysclk ns t sd last sck edge to nss rising 2*t sysclk ns t sez nss falling to miso valid 4*t sysclk ns t sdz nss rising to miso high-z 4*t sysclk ns t ckh sck high time 5*t sysclk ns t ckl sck low time 5*t sysclk ns t sis mosi valid to sck sample edge 2*t sysclk ns t sih sck sample edge to mosi change 2*t sysclk ns t soh sck shift edge to miso change 4*t sysclk ns t slh last sck edge to miso change (ckpha = 1 only) 6*t sysclk 8*t sysclk ns ? t sysclk is equal to one period of the device system clock (sysclk).
c8051f320/1 rev. 1.1 217 19. timers each mcu includes four counter/timers: two are 16-bit counter/timers compatible with those found in the standard 8051, and two are 16-bit auto-reload timer for use with th e adc, smbus, usb (frame meas urements), or for general purpose use. these timers can be used to measure time interval s, count external events and generate periodic interrupt requests. timer 0 and timer 1 are nearly identical an d have four primary modes of operation. timer 2 and timer 3 offer 16-bit and split 8-bit timer functionality with auto-reload. timers 0 and 1 may be clocked by one of five sources, de termined by the timer mode select bits (t1m-t0m) and the clock scale bits (sca1-sca0). the clock scale bits define a pr e-scaled clock from which timer 0 and/or timer 1 may be clocked (see figure 19.6 for pre-scaled clock selection). timer 0/1 may then be configured to use this pre-s caled clock signal or the system clock. timer 2 and timer 3 may be clocked by the system clock, the system clock divided by 12, or the external oscillator clock source divided by 8. timer 0 and timer 1 may also be operated as counters. when functio ning as a counter, a count er/timer register is incremented on each high-to-low tr ansition at the selected input pin (t0 or t1 ). events with a fr equency of up to one- fourth the system clock's frequency can be counted. the input signal need not be periodic, but it should be held at a given level for at least two full system clock cycles to ensure the level is properly sampled. 19.1. timer 0 and timer 1 each timer is implemented as a 16-bit register accessed as two separate bytes: a low byte (tl0 or tl1) and a high byte (th0 or th1). the counter/timer control register (tco n) is used to enable timer 0 and timer 1 as well as indicate status. timer 0 interrupts can be enabled by setting the et0 bit in the ie register ( section ?8.3.5. interrupt register descriptions? on page 61 ); timer 1 interrupts can be enabled by setting the et1 bit in the ie register ( sec - tion 8.3.5 ). both counter/timers operate in one of four primary modes selected by setting the mode select bits t1m1- t0m0 in the counter/timer mode register (tmod). each timer can be configured independently. each operating mode is described below. 19.1.1. mode 0: 13-bit counter/timer timer 0 and timer 1 operate as 13-bit counter/timers in m ode 0. the following describes the configuration and oper - ation of timer 0. however, both timers operate identica lly, and timer 1 is configured in the same manner as described for timer 0. the th0 register holds the eight msbs of the 13-bit counter/timer. tl0 holds the five lsbs in bit positions tl0.4- tl0.0. the three upper bits of tl0 (tl0.7-tl0.5) are inde terminate and should be masked out or ignored when read - ing. as the 13-bit timer register increments and overflows from 0x1fff (all ones) to 0x0000, the timer overflow flag tf0 (tcon.5) is set and an interrupt will occur if timer 0 interrupts are enabled. the c/t0 bit (tmod.2) selects the counter /timer's clock source. when c/t0 is set to logic 1, high-to-low transitions at the selected timer 0 input pin (t0) increment the timer register (refer to section ?14.1. priority crossbar decoder? on page 129 for information on selecting and configuring external i/o pins). clearing c/t selects the clock defined by the t0m bit (ckcon.3). when t0m is set, timer 0 is clocked by the system clock. when t0m is cleared, timer 0 is clocked by the source sel ected by the clock scale bits in ckcon (see figure 19.6 ). timer 0 and timer 1 modes: timer 2 modes: timer 3 modes: 13-bit counter/timer 16-bit timer with auto-reload 16-bit timer with auto-reload 16-bit counter/timer 8-bit counter/timer with auto-reload two 8-bit timers with auto-reload two 8-bit timers with auto-reload two 8-bit counter/timers (timer 0 only)
c8051f320/1 218 rev. 1.1 setting the tr0 bit (tcon.4) enables the timer when either gate0 (tmod.3) is logic 0 or the input signal /int0 is active as defined by bit in0pl in register int01cf (see figure 8.13 ). setting gate0 to ?1? allows the timer to be controlled by the external input signal /int0 (see section ?8.3.5. interrupt register descriptions? on page 61 ), facilitating pulse width measurements. setting tr0 does not force the timer to reset. the timer regist ers should be loaded with the desired initial value before the timer is enabled. tl1 and th1 form the 13-bit register for timer 1 in the sa me manner as described abov e for tl0 and th0. timer 1 is configured and controlled using the relevant tcon and tmod bits just as with timer 0. the input signal /int1 is used with timer 1; the /int1 polarity is defined by bit in1pl in register int01cf (see figure 8.13 ). 19.1.2. mode 1: 16-bit counter/timer mode 1 operation is the same as mode 0, except that the counter/timer register s use all 16 bits. th e counter/timers are enabled and configured in mode 1 in the same manner as for mode 0. tr0 gate0 /int0 counter/timer 0xxdisabled 1 0 x enabled 110disabled 111enabled x = don't care figure 19.1. t0 mode 0 block diagram tclk tl0 (5 bits) th0 (8 bits) tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt tr0 0 1 0 1 sysclk pre-scaled clock ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmod t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 gate0 /int0 t0 crossbar int01cf i n 1 s l 1 i n 1 s l 0 i n 1 s l 2 i n 1 p l i n 0 p l i n 0 s l 2 i n 0 s l 1 i n 0 s l 0 in0pl xor
c8051f320/1 rev. 1.1 219 19.1.3. mode 2: 8-bit counter/timer with auto-reload mode 2 configures timer 0 and timer 1 to operate as 8-bit counter/timers with automatic reload of the start value. tl0 holds the count and th0 holds the re load value. when the coun ter in tl0 overflows from all ones to 0x00, the timer overflow flag tf0 (tcon.5) is set and the counter in tl0 is reloaded from th0. if timer 0 interrupts are enabled, an interrupt will occur when th e tf0 flag is set. the reload value in th0 is not changed. tl0 must be initial - ized to the desired value before enabling the timer for the first count to be corr ect. when in mode 2, timer 1 operates identically to timer 0. both counter/timers are enabled and conf igured in mode 2 in the same manner as mode 0. setting the tr0 bit (tcon.4) enables the timer when either gate0 (tmod.3) is logic 0 or when the input signal /int0 is active as defined by bit in0pl in register int01cf (see section ?8.3.2. external interru pts? on page 59 for details on the external input sign als /int0 and /int1) . figure 19.2. t0 mode 2 block diagram tclk tmod t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt tl0 (8 bits) reload th0 (8 bits) 0 1 0 1 sysclk pre-scaled clock int01cf i n 1 s l 1 i n 1 s l 0 i n 1 s l 2 i n 1 p l i n 0 p l i n 0 s l 2 i n 0 s l 1 i n 0 s l 0 tr0 gate0 in0pl xor /int0 t0 crossbar ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m
c8051f320/1 220 rev. 1.1 19.1.4. mode 3: two 8-bit counter/timers (timer 0 only) in mode 3, timer 0 is configured as two separate 8-bit co unter/timers held in tl0 and th0. the counter/timer in tl0 is controlled using the timer 0 control/status bits in tcon and tmod: tr0, c/t0, gate0 and tf0. tl0 can use either the system clock or an external input signal as its timebase. the th0 register is restricted to a timer function sourced by the system clock or prescaled clock. th0 is enabled using the timer 1 run control bit tr1. th0 sets the timer 1 overflow flag tf1 on overflow a nd thus controls the timer 1 interrupt. timer 1 is inactive in mode 3. when timer 0 is operating in mode 3, timer 1 can be operated in modes 0, 1 or 2, but cannot be clocked by external signals nor set the tf1 flag and generate an interrupt. however, the timer 1 overflow can be used to generate baud rates for the smbus and/or uart, and/or initiate adc c onversions. while timer 0 is operating in mode 3, timer 1 run control is handled through its mode settings. to run timer 1 while timer 0 is in mode 3, set the timer 1 mode as 0, 1, or 2. to disable timer 1, configure it for mode 3. figure 19.3. t0 mode 3 block diagram tl0 (8 bits) tmod 0 1 tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt interrupt 0 1 sysclk pre-scaled clock tr1 th0 (8 bits) t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 tr0 gate0 in0pl xor /int0 t0 crossbar ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m
c8051f320/1 rev. 1.1 221 figure 19.4. tcon: timer control register bit7: tf1: timer 1 overflow flag. set by hardware when timer 1 overflows. this flag can be cleared by softwa re but is automatically cleared when the cpu vectors to th e timer 1 interrupt service routine. 0: no timer 1 overflow detected. 1: timer 1 has overflowed. bit6: tr1: timer 1 run control. 0: timer 1 disabled. 1: timer 1 enabled. bit5: tf0: timer 0 overflow flag. set by hardware when timer 0 overflows. this flag can be cleared by softwa re but is automatically cleared when the cpu vectors to th e timer 0 interrupt service routine. 0: no timer 0 overflow detected. 1: timer 0 has overflowed. bit4: tr0: timer 0 run control. 0: timer 0 disabled. 1: timer 0 enabled. bit3: ie1: external interrupt 1. this flag is set by hardware when an edge/level of type defined by it 1 is detected. it can be cleared by software but is automatically cleared when the cpu vectors to the external interrupt 1 service routine if it1 = 1. when it1 = 0, this flag is set to ?1? when /int1 is activ e as defined by bit in1pl in register int01cf (see figure 8.13). bit2: it1: interrupt 1 type select. this bit selects whether the configured /int1 interrup t will be edge or level sensitive. /int1 is con- figured active low or high by the in1pl bit in the it01cf register (see figure 8.13). 0: /int1 is level triggered. 1: /int1 is edge triggered. bit1: ie0: external interrupt 0. this flag is set by hardware when an edge/level of type defined by it 0 is detected. it can be cleared by software but is automatically cleared when the cpu vectors to the external interrupt 0 service routine if it0 = 1. when it0 = 0, this flag is set to ?1? when /int0 is activ e as defined by bit in0pl in register int01cf (see figure 8.13). bit0: it0: interrupt 0 type select. this bit selects whether the configured /int0 interrup t will be edge or level sensitive. /int0 is con- figured active low or high by the in0pl bit in register it01cf (see figure 8.13). 0: /int0 is level triggered. 1: /int0 is edge triggered. r/w r/w r/w r/w r/w r/w r/w r/w reset value tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0x88
c8051f320/1 222 rev. 1.1 figure 19.5. tmod: timer mode register bit7: gate1: timer 1 gate control. 0: timer 1 enabled when tr1 = 1 irrespective of /int1 logic level. 1: timer 1 enabled only when tr1 = 1 and /int1 is active as defined by bit in1pl in register int01cf (see figure 8.13). bit6: c/t1: counter/timer 1 select. 0: timer function: timer 1 incremented by clock defined by t1m bit (ckcon.4). 1: counter function: timer 1 incremented by high-to-low transitions on external input pin (t1). bits5-4: t1m1-t1m0: timer 1 mode select. these bits select the timer 1 operation mode. bit3: gate0: timer 0 gate control. 0: timer 0 enabled when tr0 = 1 irrespective of /int0 logic level. 1: timer 0 enabled only when tr0 = 1 and /int0 is active as defined by bit in0pl in register int01cf (see figure 8.13). bit2: c/t0: counter/timer select. 0: timer function: timer 0 incremented by clock defined by t0m bit (ckcon.3). 1: counter function: timer 0 incremented by high-to-low transitions on external input pin (t0). bits1-0: t0m1-t0m0: timer 0 mode select. these bits select the timer 0 operation mode. r/w r/w r/w r/w r/w r/w r/w r/w reset value gate1 c/t1 t1m1 t1m0 gate0 c/t0 t0m1 t0m0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x89 t1m1 t1m0 mode 0 0 mode 0: 13-bit counter/timer 0 1 mode 1: 16-bit counter/timer 1 0 mode 2: 8-bit counter/timer with auto-reload 1 1 mode 3: timer 1 inactive t0m1 t0m0 mode 0 0 mode 0: 13-bit counter/timer 0 1 mode 1: 16-bit counter/timer 1 0 mode 2: 8-bit counter/timer with auto-reload 1 1 mode 3: two 8-bit counter/timers
c8051f320/1 rev. 1.1 223 figure 19.6. ckcon: clock control register bit7: t3mh: timer 3 high byte clock select. this bit selects the clock supplied to the timer 3 high byte if timer 3 is configured in split 8-bit timer mode. t3mh is ignored if timer 3 is in any other mode. 0: timer 3 high byte uses the clock defined by the t3xclk bit in tmr3cn. 1: timer 3 high byte uses the system clock. bit6: t3ml: timer 3 low byte clock select. this bit selects the clock supplied to timer 3. if timer 3 is configured in split 8-bit timer mode, this bit selects the clock supplied to the lower 8-bit timer. 0: timer 3 low byte uses the clock defined by the t3xclk bit in tmr3cn. 1: timer 3 low byte uses the system clock. bit5: t2mh: timer 2 high byte clock select. this bit selects the clock supplied to the timer 2 high byte if timer 2 is configured in split 8-bit timer mode. t2mh is ignored if timer 2 is in any other mode. 0: timer 2 high byte uses the clock defined by the t2xclk bit in tmr2cn. 1: timer 2 high byte uses the system clock. bit4: t2ml: timer 2 low byte clock select. this bit selects the clock supplied to timer 2. if timer 2 is configured in split 8-bit timer mode, this bit selects the clock supplied to the lower 8-bit timer. 0: timer 2 low byte uses the clock defined by the t2xclk bit in tmr2cn. 1: timer 2 low byte uses the system clock. bit3: t1m: timer 1 clock select. this select the clock source supplied to timer 1. t1m is ignored when c/t1 is set to logic 1. 0: timer 1 uses the clock defined by the prescale bits, sca1-sca0. 1: timer 1 uses the system clock. bit2: t0m: timer 0 clock select. this bit selects the clock source supplied to timer 0. t0m is ignored when c/t0 is set to logic 1. 0: counter/timer 0 uses the clock defined by the prescale bits, sca1-sca0. 1: counter/timer 0 uses the system clock. bits1-0: sca1-sca0: timer 0/1 prescale bits. these bits control the division of the clock supplied to timer 0 and/or timer 1 if configured to use prescaled clock inputs. r/w r/w r/w r/w r/w r/w r/w r/w reset value t3mh t3ml t2mh t2ml t1m t0m sca1 sca0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x8e sca1 sca0 prescaled clock 0 0 system clock divided by 12 0 1 system clock divided by 4 1 0 system clock divided by 48 1 1 external clock divided by 8 note: external clock divided by 8 is synchronized with the system clock.
c8051f320/1 224 rev. 1.1 figure 19.7. tl0: timer 0 low byte bits 7-0: tl0: timer 0 low byte. the tl0 register is the low byte of the 16-bit timer 0. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x8a figure 19.8. tl1: timer 1 low byte bits 7-0: tl1: timer 1 low byte. the tl1 register is the low byte of the 16-bit timer 1. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x8b figure 19.9. th0: timer 0 high byte bits 7-0: th0: timer 0 high byte. the th0 register is the high byte of the 16-bit timer 0. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x8c figure 19.10. th1: timer 1 high byte bits 7-0: th1: timer 1 high byte. the th1 register is the high byte of the 16-bit timer 1. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x8d
c8051f320/1 rev. 1.1 225 19.2. timer 2 timer 2 is a 16-bit timer formed by two 8-bit sfrs: tm r2l (low byte) and tmr2h (high byte). timer 2 may oper - ate in 16-bit auto-reload mode, (split) 8-bit auto-reloa d mode, or usb start-of-frame (sof) capture mode. the timer 2 operation mode is defined by the t2sp lit (tmr2cn.3) and t2sof (tmr2cn.4) bits. timer 2 may be clocked by the system clock, the system clock divided by 12, or the external oscillator source divided by 8. the external clock mode is ideal for real-time clock (rtc) functionality, wh ere the internal oscillator drives the system clock while timer 2 (and/or the pca) is clocked by an external precision oscillator. note that the external oscillator source divided by 8 is synchronized with the system clock. 19.2.1. 16-bit timer with auto-reload when t2split = ?0? and t2sof = ?0?, timer 2 operates as a 16-bit timer with auto-reload. timer 2 can be clocked by sysclk, sysclk divided by 12, or the external oscillator clock source divided by 8. as the 16-bit timer register increments and overflows from 0xffff to 0x0000, the 16-bi t value in the timer 2 reload registers (tmr2rlh and tmr2rll) is loaded into the timer 2 register as shown in figure 19.11 , and the timer 2 high byte overflow flag (tmr2cn.7) is set. if timer 2 interrupt s are enabled (if ie.5 is set), an interrupt will be generated on each timer 2 overflow. additionally, if timer 2 interrupts are enabled an d the tf2len bit is set (tmr 2cn.5), an interrupt will be generated each time the lower 8 bits (tmr2l) overflow fr om 0xff to 0x00. figure 19.11. timer 2 16-bit mode block diagram external clock / 8 sysclk / 12 sysclk tmr2l tmr2h tmr2rll tmr2rlh reload tclk 0 1 tr2 tmr2cn t2split t2sof tf2l tf2h t2xclk tr2 0 1 t2xclk interrupt tf2len to adc, smbus to smbus tl2 overflow ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m
c8051f320/1 226 rev. 1.1 19.2.2. 8-bit timers with auto-reload when t2split = ?1? and t2sof = ?0?, timer 2 operates as two 8-bit timers (tmr2h and tmr2l). both 8-bit tim - ers operate in auto-reload mode as shown in figure 19.12 . tmr2rll holds the reload value for tmr2l; tmr2rlh holds the reload value for tmr2h. the tr2 bit in tmr2cn handles the run control for tmr2h. tmr2l is always running when configured for 8-bit mode. each 8-bit timer may be configured to use sysclk, sysclk divided by 12, or the external oscillator clock source divided by 8. the timer 2 clock select bits (t2mh and t2ml in ckcon) select either sysclk or the clock defined by the timer 2 external clock select bit (t2xclk in tmr2cn), as follows: the tf2h bit is set when tmr2h overflows from 0xff to 0x00; the tf2l bit is set when tmr2l overflows from 0xff to 0x00. when timer 2 interrupts are enabled (ie.5), an interrupt is generated each time tmr2h overflows. if timer 2 interrupts are enabled and tf2len (tmr2cn.5) is set, an interrupt is genera ted each time either tmr2l or tmr2h overflows. when tf2len is enab led, software must check the tf2h and tf2l flags to determine the source of the timer 2 interrupt. the tf2h and tf2l interr upt flags are not cleared by hardware and must be manu - ally cleared by software . t2mh t2xclk tmr2h clock source t2ml t2xclk tmr2l clock source 0 0 sysclk / 12 0 0 sysclk / 12 0 1 external clock / 8 0 1 external clock / 8 1 x sysclk 1 x sysclk figure 19.12. timer 2 8- bit mode block diagram sysclk tclk 0 1 tr2 external clock / 8 sysclk / 12 0 1 t2xclk 1 0 tmr2h tmr2rlh reload reload tclk tmr2l tmr2rll interrupt tmr2cn t2split t2sof tf2len tf2l tf2h t2xclk tr2 to adc, smbus to smbus ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m
c8051f320/1 rev. 1.1 227 19.2.3. usb start-of-frame capture when t2sof = ?1?, timer 2 operates in usb start-of-frame (sof) capture mode. when t2split = ?0?, timer 2 counts up and overflows from 0xffff to 0x0000. each time a usb sof is r eceived, the contents of the timer 2 reg - isters (tmr2h:tmr2l) are latched into the timer 2 reload registers (tmr2rlh:tmr2rll). a timer 2 interrupt is generated if enabled. this mode can be used to calibra te the system clock or external oscillator against the known usb host sof clock. when t2split = ?1?, the timer 2 registers (tmr2h and tmr2l) act as tw o 8-bit counters. each counter counts up independently and overflows from 0xff to 0x00. each time a usb sof is received, the contents of the timer 2 reg - isters are latched into the timer 2 reload registers (tmr2rlh and tmr2rll). a timer 2 interrupt is generated if enabled. external clock / 8 sysclk / 12 sysclk tmr2l tmr2h tmr2rll tmr2rlh tclk 0 1 tr2 0 1 interrupt to adc, smbus to smbus tl2 overflow ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m capture usb start-of-frame (sof) enable tmr2cn t f 2 h t f 2 l t 2 x c l k t r 2 t f 2 l e n t 2 s o f t 2 s p l i t figure 19.13. timer 2 sof capt ure mode (t2split = ?0?) sysclk tclk 0 1 tr2 external clock / 8 sysclk / 12 0 1 1 0 tmr2h tmr2rlh tclk tmr2l tmr2rll to adc, smbus to smbus ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmr2cn t f 2 h t f 2 l t 2 x c l k t r 2 t f 2 l e n t 2 s o f t 2 s p l i t usb start-of-frame (sof) capture enable capture interrupt figure 19.14. timer 2 sof capt ure mode (t2split = ?1?)
c8051f320/1 228 rev. 1.1 bit7: tf2h: timer 2 high byte overflow flag. set by hardware when the timer 2 high byte overflo ws from 0xff to 0x00. in 16 bit mode, this will occur when timer 2 overflows from 0xffff to 0x0000. when the timer 2 interrupt is enabled, set- ting this bit causes the cpu to vector to the timer 2 interrupt service routine. tf2h is not automati- cally cleared by hardware and must be cleared by software. bit6: tf2l: timer 2 low byte overflow flag. set by hardware when the timer 2 low byte overflows from 0xff to 0x00. when this bit is set, an interrupt will be generated if tf2len is set and ti mer 2 interrupts are enabled. tf2l will set when the low byte overflows regardless of the timer 2 mode . this bit is not automatically cleared by hard- ware. bit5: tf2len: timer 2 low byte interrupt enable. this bit enables/disables timer 2 low byte interr upts. if tf2len is set and timer 2 interrupts are enabled, an interrupt will be generated when the low byte of timer 2 overflows. 0: timer 2 low byte interrupts disabled. 1: timer 2 low byte interrupts enabled. bit4: t2sof: timer 2 start-of-frame capture enable 0: sof capture disabled. 1: sof capture enabled. each time a usb sof is received, the contents of the timer 2 registers (tmr2h and tmr2l) are latched into the time r 2 reload registers (tmr2rlh and tmr2rlh), and a timer 2 interrupt is generated (if enabled). bit3: t2split: timer 2 split mode enable. when this bit is set, timer 2 operates as two 8-bit timers with auto-reload. 0: timer 2 operates in 16-bit auto-reload mode. 1: timer 2 operates as two 8-bit auto-reload timers. bit2: tr2: timer 2 run control. this bit enables/disables timer 2. in 8-bit mode , this bit enables/disables tmr2h only; tmr2l is always enabled in this mode. 0: timer 2 disabled. 1: timer 2 enabled. bit1: unused. read = 0b. write = don?t care. bit0: t2xclk: timer 2 external clock select. this bit selects the external clock source for timer 2. if timer 2 is in 8-bit mode, this bit selects the external oscillator clock source for both timer byt es. however, the timer 2 clock select bits (t2mh and t2ml in register ckcon) may still be used to select between the extern al clock and the system clock for either timer. 0: timer 2 external clock selection is the system clock divided by 12. 1: timer 2 external clock selection is the external cl ock divided by 8. note that the external oscillator source divided by 8 is synchronized with the system clock. r/w r/w r/w r/w r/w r/w r/w r/w reset value tf2h tf2l tf2len t2sof t2split tr2 - t2xclk 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xc8 figure 19.15. tmr2cn: timer 2 control register
c8051f320/1 rev. 1.1 229 bits 7-0: tmr2rll: timer 2 reload register low byte. tmr2rll holds the low byte of the reload value for timer 2 when operating in auto-reload mode, or the captured value of the tmr2 l register in capture mode. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xca figure 19.16. tmr2rll: timer 2 reload register low byte figure 19.17. tmr2rlh: timer 2 reload register high byte bits 7-0: tmr2rlh: timer 2 re load register high byte. the tmr2rlh holds the high byte of the reload value for timer 2 when operating in auto-reload mode, or the captured value of the tmr2h register in capture mode. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xcb figure 19.18. tmr2l: timer 2 low byte bits 7-0: tmr2l: timer 2 low byte. in 16-bit mode, the tmr2l register contains the low byte of the 16-bit timer 2. in 8-bit mode, tmr2l contains the 8-bit low byte timer value. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xcc figure 19.19. tmr2h timer 2 high byte bits 7-0: tmr2h: timer 2 high byte. in 16-bit mode, the tmr2h register contains the high byte of the 16-bit timer 2. in 8-bit mode, tmr2h contains the 8-bit high byte timer value. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xcd
c8051f320/1 230 rev. 1.1 19.3. timer 3 timer 3 is a 16-bit timer formed by two 8-bit sfrs: tm r3l (low byte) and tmr3h (high byte). timer 3 may oper - ate in 16-bit auto-reload mode, (split) 8-bit auto-reloa d mode, or usb start-of-frame (sof) capture mode. the timer 3 operation mode is defined by the t3sp lit (tmr3cn.3) and t3sof (tmr2cn.4) bits. timer 3 may be clocked by the system clock, the system clock divided by 12, or the external oscillator source divided by 8. the external clock mode is ideal for real-time clock (rtc) functionality, wh ere the internal oscillator drives the system clock while timer 3 (and/or the pca) is clocked by an external precision oscillator. note that the external oscillator source divided by 8 is synchronized with the system clock. 19.3.1. 16-bit timer with auto-reload when t3split (tmr3cn.3) is zero, timer 3 operates as a 16-bit timer with auto-reload. timer 3 can be clocked by sysclk, sysclk divided by 12, or the external oscillator clock source divided by 8. as the 16-bit timer register increments and overflows from 0xffff to 0x0000, the 16-bi t value in the timer 3 reload registers (tmr3rlh and tm3rll) is loaded into the timer 3 register as shown in figure 19.11 , and the timer 3 high byte overflow flag (tmr3cn.7) is set. if timer 3 interrupt s are enabled (if ie.5 is set), an interrupt will be generated on each timer 3 overflow. additionally, if timer 3 interrupts are enabled an d the tf3len bit is set (tmr 3cn.5), an interrupt will be generated each time the lower 8 bits (tmr3l) overflow fr om 0xff to 0x00. figure 19.20. timer 3 16-bit mode block diagram external clock / 8 sysclk / 12 sysclk tmr3l tmr3h tmr3rll tmr3rlh reload tclk 0 1 tr3 tmr3cn t3split t3sof tf3l tf3h t3xclk tr3 0 1 t3xclk interrupt tf3len to adc ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m
c8051f320/1 rev. 1.1 231 19.3.2. 8-bit timers with auto-reload when t3split is set, timer 3 operates as two 8-bit timers (tmr3h and tmr3l). both 8- bit timers operate in auto- reload mode as shown in figure 19.12 . tmr3rll holds the reload value fo r tmr3l; tmr3rlh holds the reload value for tmr3h. the tr3 bit in tmr3cn handles the r un control for tmr3h. tmr3l is always running when configured for 8-bit mode. each 8-bit timer may be configured to use sysclk, sysclk divided by 12, or the external oscillator clock source divided by 8. the timer 3 clock select bits (t3mh and t3ml in ckcon) select either sysclk or the clock defined by the timer 3 external clock select bit (t3xclk in tmr3cn), as follows: the tf3h bit is set when tmr3h overflows from 0xff to 0x00; the tf3l bit is set when tmr3l overflows from 0xff to 0x00. when timer 3 interrupts are enabled (ie.5), an interrupt is generated each time tmr3h overflows. if timer 3 interrupts are enabled and tf3len (tmr3cn.5) is set, an interrupt is genera ted each time either tmr3l or tmr3h overflows. when tf3len is enab led, software must check the tf3h and tf3l flags to determine the source of the timer 3 interrupt. the tf3h and tf3l interr upt flags are not cleared by hardware and must be manu - ally cleared by software . t3mh t3xclk tmr3h clock source t3ml t3xclk tmr3l clock source 0 0 sysclk / 12 0 0 sysclk / 12 0 1 external clock / 8 0 1 external clock / 8 1 x sysclk 1 x sysclk figure 19.21. timer 3 8- bit mode block diagram sysclk tclk 0 1 tr3 external clock / 8 sysclk / 12 0 1 t3xclk 1 0 tmr3h tmr3rlh reload reload tclk tmr3l tmr3rll interrupt tmr3cn t3split t3sof tf3len tf3l tf3h t3xclk tr3 ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m to adc
c8051f320/1 232 rev. 1.1 19.3.3. usb start-of-frame capture when t3sof = ?1?, timer 3 operates in usb start-of-frame (sof) capture mode. when t3split = ?0?, timer 3 counts up and overflows from 0xffff to 0x0000. each time a usb sof is received, the contents of the timer 3 reg - isters (tmr3h:tmr3l) are latched into the timer 3 reload registers (tmr3rlh:tmr3rll). a timer 3 interrupt is generated if enabled. this mode can be used to calibra te the system clock or external oscillator against the known usb host sof clock. when t3split = ?1?, the timer 3 registers (tmr3h and tmr3l) act as tw o 8-bit counters. each counter counts up independently and overflows from 0xff to 0x00. each time a usb sof is received, the contents of the timer 3 reg - isters are latched into the timer 3 reload registers (tmr3rlh and tmr3rll). a timer 3 interrupt is generated if enabled. figure 19.22. timer 3 sof capture mode (t3split = ?0?) external clock / 8 sysclk / 12 sysclk tmr3l tmr3h tmr3rll tmr3rlh tclk 0 1 tr3 0 1 interrupt to adc ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m capture usb start-of-frame (sof) enable tmr3cn t f 3 h t f 3 l t 3 x c l k t r 3 t f 3 l e n t 3 s o f t 3 s p l i t sysclk tclk 0 1 tr3 external clock / 8 sysclk / 12 0 1 1 0 tmr3h tmr3rlh tclk tmr3l tmr3rll to adc ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmr3cn t f 3 h t f 3 l t 3 x c l k t r 3 t f 3 l e n t 3 s o f t 3 s p l i t usb start-of-frame (sof) capture enable capture interrupt figure 19.23. timer 3 sof capture mode (t3split = ?1?)
c8051f320/1 rev. 1.1 233 bit7: tf3h: timer 3 high byte overflow flag. set by hardware when the timer 3 high byte overflo ws from 0xff to 0x00. in 16 bit mode, this will occur when timer 3 overflows from 0xffff to 0x0000. when the timer 3 interrupt is enabled, set- ting this bit causes the cpu to vector to the timer 3 interrupt service routine. tf3h is not automati- cally cleared by hardware and must be cleared by software. bit6: tf3l: timer 3 low byte overflow flag. set by hardware when the timer 3 low byte overflows from 0xff to 0x00. when this bit is set, an interrupt will be generated if tf3len is set and ti mer 3 interrupts are enabled. tf3l will set when the low byte overflows regardless of the timer 3 mode . this bit is not automatically cleared by hard- ware. bit5: tf3len: timer 3 low byte interrupt enable. this bit enables/disables timer 3 low byte interr upts. if tf3len is set and timer 3 interrupts are enabled, an interrupt will be generated when the lo w byte of timer 3 overflows. this bit should be cleared when operating timer 3 in 16-bit mode. 0: timer 3 low byte interrupts disabled. 1: timer 3 low byte interrupts enabled. bit4: t3sof: timer 3 start-of-frame capture enable 0: sof capture disabled. 1: sof capture enabled. each time a usb sof is received, the contents of the timer 3 registers (tmr3h and tmr3l) are latched into the time r3 reload registers (tmr3rlh and tmr3rlh), and a timer 3 interrupt is generated (if enabled). bit3: t3split: timer 3 split mode enable. when this bit is set, timer 3 operates as two 8-bit timers with auto-reload. 0: timer 3 operates in 16-bit auto-reload mode. 1: timer 3 operates as two 8-bit auto-reload timers. bit2: tr3: timer 3 run control. this bit enables/disables timer 3. in 8-bit mode , this bit enables/disables tmr3h only; tmr3l is always enabled in this mode. 0: timer 3 disabled. 1: timer 3 enabled. bit1: unused. read = 0b. write = don?t care. bit0: t3xclk: timer 3 external clock select. this bit selects the external clock source for timer 3. if timer 3 is in 8-bit mode, this bit selects the external oscillator clock source for both timer byt es. however, the timer 3 clock select bits (t3mh and t3ml in register ckcon) may still be used to select between the extern al clock and the system clock for either timer. 0: timer 3 external clock selection is the system clock divided by 12. 1: timer 3 external clock selection is the external cl ock divided by 8. note that the external oscillator source divided by 8 is synchronized with the system clock. r/w r/w r/w r/w r/w r/w r/w r/w reset value tf3h tf3l tf3len t3sof t3split tr3 - t3xclk 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x91 figure 19.24. tmr3cn: timer 3 control register
c8051f320/1 234 rev. 1.1 bits 7-0: tmr3rll: timer 3 reload register low byte. tmr3rll holds the low byte of the reload value for timer 3 when operating in auto-reload mode, or the captured value of the tmr3l regist er when operating in capture mode. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x92 figure 19.25. tmr3rll: timer 3 reload register low byte figure 19.26. tmr3rlh: timer 3 reload register high byte bits 7-0: tmr3rlh: timer 3 re load register high byte. the tmr3rlh holds the high byte of the reload value for timer 3 when operating in auto-reload mode, or the captured value of the tmr3h re gister when operating in capture mode. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x93 figure 19.27. tmr3l: timer 3 low byte bits 7-0: tmr3l: timer 3 low byte. in 16-bit mode, the tmr3l register contains the low byte of the 16-bit timer 3. in 8-bit mode, tmr3l contains the 8-bit low byte timer value. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x94 figure 19.28. tmr3h timer 3 high byte bits 7-0: tmr3h: timer 3 high byte. in 16-bit mode, the tmr3h register contains the high byte of the 16-bit timer 3. in 8-bit mode, tmr3h contains the 8-bit high byte timer value. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x95
c8051f320/1 rev. 1.1 235 20. programmable co unter array (pca0) the programmable counter array (pca0) provides enhanced timer functionality while requiring less cpu interven - tion than the standard 8051 counter/timers. the pca consists of a dedicated 16-bit counter/timer and five 16-bit cap - ture/compare modules. each capture/compare module has its own associated i/o line (cexn) which is routed through the crossbar to po rt i/o when enabled (see section ?14.1. priority crossbar decoder? on page 129 for details on configuring the crossbar). the counter/timer is driven by a programmable timeb ase that can select between six sources: system clock, system clock divided by four, system clock divided by twelve, the external oscillator clock source divided by 8, timer 0 overflow, or an external clock signal on the eci input pin. each capture/compare mod - ule may be configured to operate independently in one of six modes: edge-triggered capture, software timer, high- speed output, frequency output , 8-bit pwm, or 16-bit pwm (each mode is described in section ?20.2. capture/ compare modules? on page 237 ). the external oscillator clock option is ideal for real-time clock (rtc) functional - ity, allowing the pca to be clocked by a precision external os cillator while the internal oscillator drives the system clock. the pca is configured and controlled through the system controller's special function registers. the pca block diagram is shown in figure 20.1 important note: the pca module 4 may be used as a watchdog timer (wdt), and is enabled in this mode follow - ing a system reset. access to certa in pca registers is restricted while wdt mode is enabled. see section 20.3 for details . capture/compare module 1 capture/compare module 0 capture/compare module 2 capture/compare module 3 capture/compare module 4 / wdt cex1 eci crossbar cex2 cex3 cex4 cex0 port i/o 16-bit counter/timer pca clock mux sysclk/12 sysclk/4 timer 0 overflow eci sysclk external clock/8 figure 20.1. pca block diagram
c8051f320/1 236 rev. 1.1 20.1. pca counter/timer the 16-bit pca counter/timer consists of two 8-bit sfrs: pca0l and pca0h. pca0h is the high byte (msb) of the 16-bit counter/timer and pca0l is the low byte (lsb). reading pca0l automatically latches the value of pca0h into a ?snapshot? register; the following pca0h read accesse s this ?snapshot? register. reading the pca0l regis - ter first guarantees an accurate read ing of the entire 16-bit pca0 counter. reading pca0h or pca0l does not disturb the counter operation. the cps2-cps0 bits in the pc a0md register select the timebase for the counter/timer as shown in table 20.1 . when the counter/timer overflows from 0xffff to 0x0000, the counter overflow flag (cf) in pca0md is set to logic 1 and an interrupt request is generated if cf interr upts are enabled. setting the ecf bit in pca0md to logic 1 enables the cf flag to generate an in terrupt request. the cf bit is not auto matically cleared by hardware when the cpu vectors to the interrupt service rou tine, and must be cleared by software (note: pca0 interrupts must be glo - bally enabled before cf interrupts are recognized. pca0 interrupts are globally enabled by setting the ea bit (ie.7) and the epca0 bit in eie1 to logic 1). clearing the cidl bit in the pca0md register allows the pca to continue normal operation while the cpu is in idle mode. table 20.1. pca timebase input options cps2 cps1 cps0 timebase 0 0 0 system clock divided by 12 0 0 1 system clock divided by 4 0 1 0 timer 0 overflow 0 1 1 high-to-low transitions on eci (max rate = system clock divided by 4) 1 0 0 system clock 101 external oscillator source divided by 8 ? ? external oscillator source divided by 8 is synchronized with the system clock. figure 20.2. pca counter/timer block diagram pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 4 c c f 3 pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 idle 0 1 pca0h pca0l snapshot register to sfr bus overflow to pca interrupt system cf pca0l read to pca modules sysclk/12 sysclk/4 timer 0 overflow eci 000 001 010 011 100 101 sysclk external clock/8
c8051f320/1 rev. 1.1 237 20.2. capture/compare modules each module can be configured to op erate independently in one of six operation modes: edge-triggered capture, software timer, high speed output, frequency output, 8- bit pulse width modulator, or 16-bit pulse width modu - lator. each module has special function registers (sfrs) associated with it in the cip- 51 system controller. these registers are used to exchange da ta with a module and configure the module's mode of operation. table 20.2 summarizes the bit settings in the pca0cpmn regist ers used to select the pc a capture/compare module?s operating modes. setting the eccfn bit in a pca0cpmn regi ster enables the module's ccfn interrupt. note: pca0 interrupts must be globally enabled before individual ccf n interrupts are recognized. pca0 interrupts are globally enabled by setting the ea bit and the epca0 bit to logic 1. see figure 20.3 for details on the pca interrupt configu - ration. table 20.2. pca0cpm register settings fo r pca capture/compare modules pwm16 ecom capp capn mat tog pwm eccf operation mode x x 10000x capture triggered by positive edge on cexn x x 01000x capture triggered by negative edge on cexn x x 11000x capture triggered by transition on cexn x 1 00100x software timer x 1 00110x high speed output x 1 0 0 x 1 1 x frequency output 0 1 0 0 x 0 1 x 8-bit pulse width modulator 1 1 0 0 x 0 1 x 16-bit pulse width modulator x = don?t care figure 20.3. pca interrupt block diagram pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 4 c c f 3 pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 0 1 pca module 0 (ccf0) pca module 1 (ccf1) eccf1 0 1 eccf0 0 1 pca module 2 (ccf2) eccf2 0 1 pca module 3 (ccf3) eccf3 0 1 pca module 4 (ccf4) eccf4 pca counter/ timer overflow 0 1 interrupt priority decoder epca0 0 1 ea 0 1 pca0cpmn (for n = 0 to 4) p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n
c8051f320/1 238 rev. 1.1 20.2.1. edge-triggered capture mode in this mode, a valid transition on the cexn pin causes th e pca to capture the value of the pca counter/timer and load it into the corresponding modu le's 16-bit capture/compare register (pca0cpln and pca0cphn). the cappn and capnn bits in the pca0cpmn register are used to select the type of transition that triggers the capture: low-to- high transition (positive edge), high-to-low transition (negativ e edge), or either transition (positive or negative edge). when a capture occurs, the capture/comp are flag (ccfn) in pca0cn is set to logic 1 and an interrupt request is generated if ccf interrupts are enable d. the ccfn bit is not automatically cleared by hardware when the cpu vec - tors to the interrupt service routine, and must be cleared by software. if both cappn and capnn bits are set to logic 1, then the state of the port pin associ ated with cexn can be read directly to determine whether a rising-edge or fall - ing-edge caused the capture. note: the cexn input signal must remain high or low for at least 2 system clock cycles to be recognized by the hard - ware. figure 20.4. pca capture mode diagram pca0l pca0cpln pca timebase cexn crossbar port i/o pca0h capture pca0cphn 0 1 0 1 (to ccfn) pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 4 c c f 3 pca interrupt 0 000x x
c8051f320/1 rev. 1.1 239 20.2.2. software timer (compare) mode in software timer mode, the pca counter/timer value is co mpared to the module's 16-bit capture/compare register (pca0cphn and pca0cpln). when a match occurs, the ca pture/compare flag (ccfn) in pca0cn is set to logic 1 and an interrupt request is generated if ccf interrupt s are enabled. the ccfn bit is not automatically cleared by hardware when the cpu vectors to the interrupt servi ce routine, and must be clear ed by software. setting the ecomn and matn bits in the pca0cpmn register enables software timer mode. important note about ca pture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. wr iting to pca0cpln clears the ecomn bit to ?0?; writing to pca0cphn sets ecomn to ?1?. figure 20.5. pca software timer mode diagram match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln 00 00 0 1 x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 4 c c f 3 pca interrupt
c8051f320/1 240 rev. 1.1 20.2.3. high speed output mode in high speed out put mode, a module?s associated cexn pin is toggled each time a match occurs between the pca counter and the module's 16-bit capture/compare regist er (pca0cphn and pca0cpln) setting the togn, matn, and ecomn bits in the pca0cpmn register enables the high-speed output mode. important note about ca pture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. wr iting to pca0cpln clears the ecomn bit to ?0?; writing to pca0cphn sets ecomn to ?1?. figure 20.6. pca high speed output mode diagram match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln 0 1 00 0x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x cexn crossbar port i/o toggle 0 1 togn pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 4 c c f 3 pca interrupt
c8051f320/1 rev. 1.1 241 20.2.4. frequency output mode frequency output mode produces a pr ogrammable-frequency square wave on the module?s associated cexn pin. the capture/compare module high byte holds the number of pca clocks to count before the output is toggled. the frequency of the square wave is then defined by equation 20.1 . where f pca is the frequency of the clock selected by the c ps2-0 bits in the pca mode register, pca0md. the lower byte of the capture/compare module is compared to the pca counter low byte; on a match, cexn is toggled and the offset held in the high byte is added to the matc hed value in pca0cpln. frequency output mode is enabled by setting the ecomn, togn, and pwmn bits in the pca0cpmn register. equation 20.1. square wave frequency output f cexn f pca 2 pca 0 cphn ------------------- --------------------- - = note: a value of 0x00 in the pca0cphn register is equal to 256 for this equation. 8-bit comparator pca0l enable pca timebase match pca0cphn 8-bit adder pca0cpln adder enable cexn crossbar port i/o toggle 0 1 togn 000 x pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x enb enb 0 1 write to pca0cpln write to pca0cphn reset figure 20.7. pca frequency output mode
c8051f320/1 242 rev. 1.1 20.2.5. 8-bit pulse width modulator mode each module can be used independently to generate a pul se width modulated (pwm) output on its associated cexn pin. the frequency of the output is dependent on the timebase for the pca counter/timer. the duty cycle of the pwm output signal is varied using the module's pca0cpln capture /compare register. when the value in the low byte of the pca counter/timer (pca0l) is equal to the value in pca0cpln, the output on the cexn pin will be set. when the count value in pca0l overflows, the cexn output will be reset (see figure 20.8 ). also, when the counter/timer low byte (pca0l) overflows from 0xff to 0x00, pca0cpln is re loaded automatically with th e value stored in the mod - ule?s capture/compare high byte (pca0cphn) without softwa re intervention. setting the ecomn and pwmn bits in the pca0cpmn register enables 8-bit pulse width modulator mode. the duty cycle for 8-bit pwm mode is given by equation 20.2 . important note about ca pture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. wr iting to pca0cpln clears the ecomn bit to ?0?; writing to pca0cphn sets ecomn to ?1?. dutycycle 256 pca 0 cphn ? () 256 ------------------ ----------------- ---------------- = equation 20.2. 8-bit pwm duty cycle
c8051f320/1 rev. 1.1 243 using equation 20.2 , the largest duty cycle is 100% (pca0cphn = 0), and the smallest duty cycle is 0.39% (pca0cphn = 0xff). a 0% duty cycle may be generated by clearing the ecomn bit to ?0?. 8-bit comparator pca0l pca0cpln pca0cphn cexn crossbar port i/o enable overflow pca timebase 00x0 x q q set clr s r match pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 enb enb 0 1 write to pca0cpln write to pca0cphn reset figure 20.8. pca 8-bit pwm mode diagram
c8051f320/1 244 rev. 1.1 20.2.6. 16-bit pulse width modulator mode a pca module may also be operated in 16-bit pwm mode. in this mode, the 16-bit capture/compare module defines the number of pca clocks for the low time of the pwm signal. when the pca counter matches the module contents, the output on cexn is asserted high; when the counter overflows, cexn is asserted low. to output a varying duty cycle, new value writes should be sync hronized with pca ccfn match interrupts. 16-bit pwm mode is enabled by setting the ecomn, pwmn, and pwm16n bits in the pca0cpmn register. for a varying duty cycle, match interrupts should be enabled (eccfn = 1 and matn = 1) to help sy nchronize the capture/compare register writes. the duty cycle for 16-bit pwm mode is given by equation 20.3 . important note about ca pture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. wr iting to pca0cpln clears the ecomn bit to ?0?; writing to pca0cphn sets ecomn to ?1?. using equation 20.3 , the largest duty cycle is 10 0% (pca0cpn = 0), and the smal lest duty cycle is 0.0015% (pca0cpn = 0xffff). a 0% duty cycle may be generated by clearing the ecomn bit to ?0?. equation 20.3. 16-bit pwm duty cycle dutycycle 65536 pca 0 cpn ? () 65536 ------------------ ------------------ ---------------- - = figure 20.9. pca 16-bit pwm mode pca0cpln pca0cphn enable pca timebase 00x0 x pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 1 16-bit comparator cexn crossbar port i/o overflow q q set clr s r match pca0h pca0l enb enb 0 1 write to pca0cpln write to pca0cphn reset
c8051f320/1 rev. 1.1 245
c8051f320/1 246 rev. 1.1 20.3. watchdog timer mode a programmable watchdog timer (wdt) function is availa ble through the pca module 4. the wdt is used to gen - erate a reset if the time between write s to the wdt update register (pca0cph 4) exceed a specified limit. the wdt can be configured and enabled/di sabled as needed by software. with the wdte and/or wdlck bits set to ?1? in the pc a0md register, module 4 operates as a watchdog timer (wdt). the module 4 high byte is compared to the pca counter high byte; the module 4 low byte holds the offset to be used when wdt updates are performed. the watchdog timer is enabled on reset. writes to some pca regis - ters are restricted while th e watchdog timer is enabled. 20.3.1. watchdog timer operation while the wdt is enabled: ? pca counter is forced on. ? writes to pca0l and pca0h are not allowed. ? pca clock source bits (cps2-cps0) are frozen. ? pca idle control bit (cidl) is frozen. ? module 4 is forced into watchdog timer mode. ? writes to the module 4 mode register (pca0cpm4) are disabled. while the wdt is enabled, writes to th e cr bit will not change the pca counter state; the counter will run until the wdt is disabled. the pca counter run cont rol (cr) will read zero if the wdt is enabled but user software has not enabled the pca counter. if a match occurs between pca0cph4 and pca0h while the wdt is enabled, a reset will be generated. to prevent a wdt reset, the wdt may be updated with a write of any value to pca0cph4. upon a pca0cph4 write, pca0h plus the offset held in pca0cpl4 is loaded into pca0cph4 (see figure 20.10 ). figure 20.10. pca module 4 with watchdog timer enabled pca0h enable pca0l overflow reset pca0cpl4 8-bit adder pca0cph4 adder enable pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 match write to pca0cph4 8-bit comparator
c8051f320/1 rev. 1.1 247 note that the 8-bit offset held in pca0cph4 is compared to the upper byte of the 16-bit pca counter. this offset value is the number of pca0l overflows before a reset. up to 256 pca clocks may pass before the first pca0l overflow occurs, depending on the value of the pca0l when th e update is performed. the total offset is then given (in pca clocks) by equation 20.4 , where pca0l is the value of the pca0 l register at the time of the update. the wdt reset is generated when pca0l overflows whil e there is a match between pca0cph4 and pca0h. soft - ware may force a wdt reset by writing a ?1? to th e ccf4 flag (pca0cn.4) while the wdt is enabled. 20.3.2. watchdog timer usage to configure the wdt, pe rform the following tasks: 1. disable the wdt by writing a ?0? to the wdte bit. 2. select the desired pca clock source (with the cps2-cps0 bits). 3. load pca0cpl4 with the desired wdt update offset value. 4. configure the pca idle mode (set cidl if the wdt should be suspended while the cpu is in idle mode). 5. enable the wdt by setting the wdte bit to ?1?. 6. (optional) lock the wdt (prevent wdt disable until the next system reset) by setting the wdlck bit to ?1?. the pca clock source and idle mode select cannot be changed while the wdt is enabled. the watchdog timer is enabled by setting the wdte or wdlck bits in the pca0 md register. when wdlck is set, the wdt cannot be disabled until the next system reset. if wdlck is no t set, the wdt is disabled by clearing the wdte bit. the wdt is enabled following any reset. the pca0 counter clock defaults to the system clock divided by 12, pca0l defaults to 0x00, and pca0 cpl4 defaults to 0x00. using equation 20.4 , this results in a wdt timeout inter - val of 256 system clock cycles. table 20.3 lists some example timeout inte rvals for typical system clocks. table 20.3. watchdog timer timeout intervals ? system clock (hz) pca0cpl4 timeout interval (ms) 12,000,000 255 65.5 12,000,000 128 33.0 12,000,000 32 8.4 18,432,000 255 42.7 18,432,000 128 21.5 18,432,000 32 5.5 11,059,200 255 71.1 11,059,200 128 35.8 11,059,200 32 9.2 4,000,000 255 196.6 4,000,000 128 99.1 4,000,000 32 25.3 32,000 255 24,576.0 32,000 128 12,384.0 32,000 32 3,168.0 ? assumes sysclk / 12 as the pca cl ock source, and a pca0l value of 0x00 at the update time. ?? internal oscillator reset frequency. equation 20.4. watchdog timer offset in pca clocks offset 256 pca 0 cpl 4 () 256 pca 0 l ? () + =
c8051f320/1 248 rev. 1.1 20.4. register descriptions for pca following are detailed descriptions of the special function registers re lated to the operation of the pca. bit7: cf: pca counter/t imer overflow flag. set by hardware when the pc a counter/timer overflows from 0xffff to 0x0000. when the counter/timer overflow (cf) interrupt is enabled, setting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not auto matically cleared by hardwa re and must be cleared by software. bit6: cr: pca counter/timer run control. this bit enables/disables the pca counter/timer. 0: pca counter/timer disabled. 1: pca counter/timer enabled. bit5: unused. read = 0b, write = don't care. bit4: ccf4: pca module 4 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf4 interrupt is enabled, set- ting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automati- cally cleared by hardware and must be cleared by software. bit3: ccf3: pca module 3 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf3 interrupt is enabled, set- ting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automati- cally cleared by hardware and must be cleared by software. bit2: ccf2: pca module 2 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf2 interrupt is enabled, set- ting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automati- cally cleared by hardware and must be cleared by software. bit1: ccf1: pca module 1 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf1 interrupt is enabled, set- ting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automati- cally cleared by hardware and must be cleared by software. bit0: ccf0: pca module 0 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf0 interrupt is enabled, set- ting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automati- cally cleared by hardware and must be cleared by software. r/w r/w r/w r/w r/w r/w r/w r/w reset value cf cr - ccf4 ccf3 ccf2 ccf1 ccf0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: (bit addressable) 0xd8 figure 20.11. pca0cn: pca control register
c8051f320/1 rev. 1.1 249 figure 20.12. pca0md: pca mode register bit7: cidl: pca counter/timer idle control. specifies pca behavior when cpu is in idle mode. 0: pca continues to function normally while the system controller is in idle mode. 1: pca operation is suspended while the system controller is in idle mode. bit6: wdte: watchdog timer enable if this bit is set, pca module 4 is used as the watchdog timer. 0: watchdog timer disabled. 1: pca module 4 enabled as watchdog timer. bit5: wdlck: watchdog timer lock this bit enables and locks the watchdog timer. when wdlck is set to ?1?, the watchdog timer may not be disabled until the next system reset. 0: watchdog timer unlocked. 1: watchdog timer enabled and locked. bit4: unused. read = 0b, write = don't care. bits3-1: cps2-cps0: pca counter/timer pulse select. these bits select the timebas e source for the pca counter . bit0: ecf: pca counter/timer overflow interrupt enable. this bit sets the masking of the pca counter/timer overflow (cf) interrupt. 0: disable the cf interrupt. 1: enable a pca counter/timer overflow inte rrupt request when cf (pca0cn.7) is set. note: when the wdte bit is set to ?1?, the pca0md register cannot be modified. to change the contents of the pca0md register, the watchd og timer must first be disabled. r/w r/w r/w r/w r/w r/w r/w r/w reset value cidl wdte wdlck - cps2 cps1 cps0 ecf 01000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xd9 cps2 cps1 cps0 timebase 0 0 0 system clock divided by 12 0 0 1 system clock divided by 4 0 1 0 timer 0 overflow 011 high-to-low transitions on eci (max rate = system clock divided by 4) 1 0 0 system clock 101 external clock divided by 8 ? 1 1 0 reserved 1 1 1 reserved ? external oscillator source divided by 8 is synchronized with the system clock.
c8051f320/1 250 rev. 1.1 pca0cpmn address: pca0cpm0 = 0xda (n = 0), pca0cpm1 = 0xdb (n = 1), pca0cpm2 = 0xdc (n = 2), pca0cpm3 = 0xdd (n = 3), pca0cpm4 = 0xde (n = 4) bit7: pwm16n: 16-bit pulse width modulation enable. this bit selects 16-bit mode when pulse width modulation mode is enabled (pwmn = 1). 0: 8-bit pwm selected. 1: 16-bit pwm selected. bit6: ecomn: comparator function enable. this bit enables/disables the comparator function for pca module n. 0: disabled. 1: enabled. bit5: cappn: capture positive function enable. this bit enables/disables the positiv e edge capture for pca module n. 0: disabled. 1: enabled. bit4: capnn: capture negative function enable. this bit enables/disables the negative edge capture for pca module n. 0: disabled. 1: enabled. bit3: matn: match function enable. this bit enables/disables the match function for pca module n. when enable d, matches of the pca counter with a module's capture/com pare register cause the ccfn bit in pca0md register to be set to logic 1. 0: disabled. 1: enabled. bit2: togn: toggle function enable. this bit enables/disables the toggle function for pca module n. when enab led, matches of the pca counter with a module's capture/compare register cau se the logic level on the cexn pin to toggle. if the pwmn bit is also set to logic 1, the module operates in frequency output mode. 0: disabled. 1: enabled. bit1: pwmn: pulse width modulation mode enable. this bit enables/disables the pwm function for pca module n. when enabled, a pulse width modu- lated signal is output on the cexn pin. 8-bit pwm is used if pwm16n is cleared; 16-bit mode is used if pwm16n is set to logic 1. if the togn bit is also set, the module operat es in frequency output mode. 0: disabled. 1: enabled. bit0: eccfn: capture/compar e flag interrupt enable. this bit sets the masking of the capt ure/compare flag ( ccfn) interrupt. 0: disable ccfn interrupts. 1: enable a capture/compare flag in terrupt request when ccfn is set. r/w r/w r/w r/w r/w r/w r/w r/w reset value pwm16n ecomn cappn capnn matn togn pwmn eecfn 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xda, 0xdb, 0xdc, 0xdd, 0xde f i gure 20 . 13 . p ca0c pmn: p ca c apture /c ompare mode reg i sters
c8051f320/1 rev. 1.1 251 bits 7-0: pca0l: pca counter/timer low byte. the pca0l register holds the low byte (l sb) of the 16-bit pca counter/timer. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xf9 f i gure 20 . 14 . p ca0 l: p ca c ounter / t i mer low byte bits 7-0: pca0h: pca counter/timer high byte. the pca0h register holds the high byte (msb) of the 16-bit pca counter/timer. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xfa figure 20.15. pca0h: pca counter/timer high byte
c8051f320/1 252 rev. 1.1 figure 20.16. pca0cpln: pca capture module low byte pca0cpln address: pca0cpl0 = 0xfb (n = 0), pca0cpl1 = 0xe9 (n = 1), pca0cpl2 = 0xeb (n = 2), pca0cpl3 = 0xed (n = 3), pca0cpl4 = 0xfd (n = 4) bits7-0: pca0cpln: pca capture module low byte. the pca0cpln register hold s the low byte (lsb) of the 16-bit capture module n. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xfb, 0xe9, 0xeb, 0xed, 0xfd pca0cphn address: pca0cph0 = 0xfc (n = 0), pca0cph1 = 0xea (n = 1), pca0cph2 = 0xec (n = 2), pca0cph3 = 0xee (n = 3), pca0cph4 = 0xfe (n = 4) bits7-0: pca0cphn: pca capture module high byte. the pca0cphn register holds the high byte (msb) of the 16-bit capture module n. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xfc, 0xea, 0xec,0xee, 0xfe figure 20.17. pca0cphn: pca capture module high byte
c8051f320/1 rev. 1.1 253 21. c2 interface c8051f320/1 devices include an on-chip silicon labs 2- wire (c2) debug interface to allow flash programming, boundary scan functions, and in-system debugging with the pr oduction part installed in the end application. the c2 interface uses a clock signal (c2ck) and a bi-directional c2 data signal (c2d) to transfer information between the device and a host system. see the c2 interface specification for details on the c2 protocol. 21.1. c2 interface registers the following describes the c2 registers necessary to perform flash programming and boundary scan functions through the c2 interface. all c2 registers are accessed th rough the c2 interface as desc ribed in the c2 interface spec - ification. figure 21.1. c2add: c2 address register bits7-0: the c2add register is accessed via the c2 interf ace to select the target data register for c2 data read and data write commands. reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 address description 0x00 selects the device id register for data read instructions 0x01 selects the revision id regist er for data read instructions 0x02 selects the c2 flash programming control register for data read/write instructions 0xb4 selects the c2 flash programming da ta register for data read/write instructions figure 21.2. deviceid: c2 device id register this read-only register returns the 8-bit device id: 0x09 (c8051f320/1). reset value 00001001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
c8051f320/1 254 rev. 1.1 figure 21.3. revid: c2 revision id register this read-only register returns the 8-bit revision id: 0x01 (revision b). reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 figure 21.4. fpctl: c2 flash programming control register bits7-0 fpctl: flash programming control register. this register is used to enable flash programm ing via the c2 interface. to enable c2 flash pro- gramming, the following codes must be written in order: 0x02, 0x01. note that once c2 flash pro- gramming is enabled, a system reset must be issued to resume normal operation. reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 figure 21.5. fpdat: c2 flash programming data register bits7-0: fpdat: c2 flash pr ogramming data register. this register is used to pass flash commands , addresses, and data during c2 flash accesses. valid commands are listed below. reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 code command 0x06 flash block read 0x07 flash block write 0x08 flash page erase 0x03 device erase
c8051f320/1 rev. 1.1 255 21.2. c2 pin sharing the c2 protocol allows the c2 pins to be shared with user functions so that in-s ystem debugging, flash program - ming, and boundary scan functions may be performed. this is possible because c2 communication is typically per - formed when the device is in the halt st ate, where all on-chip peripherals and user software are stalled. in this halted state, the c2 interface can sa fely ?borrow? the c2ck (/rst) and c2d (p3. 0) pins. in most applications, external resistors are required to isolate c2 inte rface traffic from the user application. a typical is olation configuration is shown in figure 21.6 . the configuration in figure 21.6 assumes the following: 1. the user input (b) cannot change stat e while the target device is halted. 2. the /rst pin on the target device is used as an input only. additional resistors may be necessary depending on the specific application. c2d c2ck /reset (a) input (b) output (c) c2 interface master c8051fxxx figure 21.6. typical c2 pin sharing
c8051f320/1 256 rev. 1.1 contact information silicon laboratories inc. 4635 boston lane austin, tx 78735 tel: 1+(512) 416-8500 fax: 1+(512) 416-9669 toll free: 1+(877) 444-3032 email: productinfo@silabs.com internet: www.silabs.com silicon laboratories and silicon labs are trademarks of silicon laboratories inc. other products or brandnames mentioned herein are trademark s or registered trademarks of their respective holders the information in this document is believed to be accurate in al l respects at the time of publ ication but is subject to change without notice. silicon laboratories assumes no re sponsibility for errors and omissions, and disclaims responsibi lity for any consequen ces resulting from the use of information included herein. additi onally, silicon laborator ies assumes no responsibility for the fun ction- ing of undescribed features or parameters. silicon laboratories re serves the right to make change s without further notice. sili con laboratories makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpos e, nor does silicon laboratories assume any liabi lity arising out of the application or use of any product or circuit, and specifi cally disclaims any and all liability, including without limitation consequential or incident al damages. silicon laboratories product s are not designed, intended, or authorized for use in applications in tended to support or sustain life, or for any other application in which the failure of the silicon laboratories product could create a si tuation where personal injury or death may occur. should buyer purchase or use silicon laboratories prod ucts for any such unintended or unauthorized application, buyer shall indemnify and hold silicon laboratories harmless against all claims and damages.


▲Up To Search▲   

 
Price & Availability of C8051F321

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X